Adding column in a .txt file

Helle,
I want to create a .ksh script in order to realize the following :
I have a .txt file organized in a bloc of information, each bloc start with 000 as following:

000...
001...
003...
004...
000...
001...
003...
004...
.
.

My aim is to add a new column at the end of each line in order to have a unique key for each bloc as following:

000...1
001...1
003...1
004...1
000...2
001...2
003...2
004...2

.
.
thanks for your help :)!

If awk is acceptable:

awk '$0 = $0 (/^000/ ? ++_ : _)' infile 

Another one :):

awk '/^000/{ORS=++c RS}1' file

:slight_smile: Nice one!

---------- Post updated at 12:16 PM ---------- Previous update was at 12:10 PM ----------

Based on Franklin52's code:

awk 'ORS=(/^000/?++_:_)RS' infile

This is nice too! :smiley:

thank you for your help :),
i find that the command awk is very powerful:b: ! do you have a tutorial that resume different use of this command?

Some links:

Awk - A Tutorial and Introduction - by Bruce Barnett

http://www.gnu.org/manual/gawk/gawk.pdf