【发布时间】:2014-06-20 16:26:12
【问题描述】:
我在 shell 脚本中使用了一个 while 读取循环来逐行计算和编号我的 file.txt。现在我想在循环内给出确切的行数,就像我是命令 wc -l 一样。下面是我的脚本。
#!/bin/bash
let count=0
while read cdat ctim clat clon
do
h=${ctim:0:2}; # substring hours from ctim
m=${ctim:3:2};
s=${ctim:6:2};
# echo $j
if [[ $h>=11 ]]; then
if [[ $h<=18 ]] && [[ $s<=00 ]]; then
if [[ $m != 01 ]]; then # spaces around "!=" is necessary
echo "$count $LINE" $cdat $ctim $clat $clon
let count=$count+1
fi
fi
fi
done < cloud.txt
exit
输出包含如下行:
0 2014/04/00 14:44:00 26.12 -23.22
1 2014/11/21 16:05:00 19.56 -05.30
2 2014/01/31 13:55:00 02.00 31.10
3 2014/04/00 14:20:00 17.42 12.14
4 2014/07/25 15:30:00 35.25 05.90
5 2014/05/15 12:07:00 23.95 07.11
6 2014/07/29 17:34:00 44.00 17.43
7 2014/03/20 18:00:00 -11.12 -22.05
8 2014/09/21 12:00:00 06.44 41.55
我的问题是如何找到输出包含 9 行?
【问题讨论】:
-
$count有什么问题? -
您希望在输出中的哪个位置看到“9”? 9行之前?后?而不是?