Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file like this:

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

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

i want to numbering RUNs like this

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

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

how can i do that using grep or any other commands?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

One way using GNU awk:

awk '/^=+\[RUN\]=+$/ { i++; sub(/RUN/, "RUN "i) }1' file.txt 
share|improve this answer
perl -pe 'if (/=\[RUN\]=/) { $i++; s//=[RUN $i]=/; }'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.