0

I have big file which has following lines

abc_a
some lines
abc_b
some lines
abc_c
some lines
abc_d
some lines
abc_e
some lines
abc_f

I want to add number incremental starting from 1 after every abc lines something like

abc_a1
some lines
abc_b2
some lines
abc_c3
some lines
abc_d4
some lines
abc_e5
some lines
abc_f6

Is it possible with sed or awk?

1 Answer 1

2

With awk:

awk '/^abc/ { $0 = $0 (++a) } 1' file

With perl:

perl -lpe '/^abc/o and s/$/++$a/e' file

or

perl -lpe '/^abc/o and $_ .= ++$a' file

With vim:

:let a=1
::g/^abc/ s/$/\=a/ | let a+=1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.