生信喵 发表于 2024-12-12 21:10:30

SHELL7 打印字母数小于8的单词

<h2>描述</h2>
<p>写一个bash脚本以统计一个文本文件nowcoder.txt中字母数小于8的单词。<br />
示例:<br />
假设 nowcoder.txt 内容如下:</p>
<pre><code>how they are implemented and applied in computer
</code></pre>
<p>你的脚本应当输出:</p>
<pre><code>how
they
are
and
applied
in
</code></pre>
<p>说明:<br />
不用担心你输出的空格以及换行的问题</p>

生信喵 发表于 2024-12-12 21:11:17

<pre><code>#!/bin/bash
read line &lt; nowcoder.txt
for n in $line
do
if [ &quot;${#n}&quot; -lt 8 ]
then
    echo &quot;${n}&quot;
fi
done
</code></pre>
页: [1]
查看完整版本: SHELL7 打印字母数小于8的单词