我正在寻找可以让脚本执行以下操作的想法:
我有一个文本文件,例如。包含类似文本的test.txt:
#
# sectione 1
#
several
text
lines
and so on
#
# sectione 2
#
more text
and more
#
and more
# ...
#
# sectione 3
#
more
more
more
#
# sectione 4
#
...
...我需要一个可能性,只计算第二部分中的行,并排除以#开头的行
在我上面的例子中,脚本应该向我显示一个计数器,末尾有"3“,例如。
# counter_script.sh test.txt
# 3这是可能的吗?我该怎么做呢?我使用的是带有bash shell的Debian Linux。
发布于 2017-07-25 22:06:02
sed -n '/sectione 2/,/sectione 3/{/^#/!p}' test.txt | wc -l在第2节和第3节间处理数据,在行首匹配#,然后用!p打印不符合此模式的任何行。
https://stackoverflow.com/questions/45304581
复制相似问题