使用grep或任何其他命令为文件的某些内容编号


-1

我有这样一个文件:

==================================[RUN]===================================
result                : Ok
CPU time              : 0.016001 s

==================================[RUN]===================================
result                : Ok
CPU time              : 1.012010 s

我想像这样编号RUN

==================================[RUN 1]===================================
result                : Ok
CPU time              : 0.016001 s

==================================[RUN 2]===================================
result                : Ok
CPU time              : 1.012010 s

我怎么能用grep或任何其他命令呢?

Answers:


3

一种方式使用 GNU awk

awk '/^=+\[RUN\]=+$/ { i++; sub(/RUN/, "RUN "i) }1' file.txt 

4
perl -pe 'if (/=\[RUN\]=/) { $i++; s//=[RUN $i]=/; }'
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.