计算grep下面的行数,并在输出中包含filename



我想计算sed命令下面的行数,并将filename附加到输出中。

样本file.txt

Aaaaaaa
Bbbbbbb
Ccccccc
Ddddddd

我想要grep Bbbbbb并找到下面的行号并输出数字加上文件名

我试过这个cat ${samplename}.txt|sed -n 'Bbbbbbb/,$p'| wc -l,但文件名不在输出

为了知道行在哪里"Bbbbb"发现:

grep -n "Bbbbb" file.txt | cut -d ':' -f 1
// grep -n adds line number in front of the search result, this is followed by a colon.
// You get that number by splitting over that colon and take the first field.

要知道文件的行数:

wc -l file.txt

为了执行计算:

echo $((43 - 7))

把所有的东西结合起来:-)
玩得开心

最新更新