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

SHELL5 打印空行的行号

<h2>描述</h2>
<p>编写一个shell脚本以输出一个文本文件nowcoder.txt中空行的行号(空行可能连续,从1开始输出)</p>
<p>示例:<br />
假设 nowcoder.txt 内容如下:</p>
<pre><code>a
b

c

d

e


f
</code></pre>
<p>你的脚本应当输出:</p>
<pre><code>3
5
7
9
10
</code></pre>

生信喵 发表于 2024-12-12 21:05:27

<pre><code>#!/bin/bash
row=0
while read line
do
    ((row++))
    if [ &quot;$line&quot; = &quot;&quot; ];then
      echo $row
    fi
done &lt; nowcoder.txt
</code></pre>
页: [1]
查看完整版本: SHELL5 打印空行的行号