Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .