我使用 grep 从出现特定字符串的文件中获取行号。如果我希望这些行号显示在由逗号分隔的行中而不是垂直显示在一行中怎么办?
cFont=$(grep -icE "<font *" $htmlFile)
if [ $cFont -gt 0 ] ; then
echo "There are $cFont line(s) with <font> tag, they are: " >> ~/Desktop/errors.txt
grep -inE "<font *" $htmlFile |cut -f1 -d: >> ~/Desktop/errors.txt
fi
输出是
There are 4 line(s) with <font> tag, they are:
14
43
46
72
我想要它
There are 4 line(s) with <font> tag, they are:
14, 43, 46, 72
最佳答案
使用:
grep -inE "<font *" $htmlFile |cut -f1 -d:| tr '\n' ','|sed -e "s/,$//" >> ~/Desktop/errors.tr
关于bash - 从 grep 打印行号,用逗号分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24268709/