string - bash: changing column fields by current number of occurence/running number -


i got stuck rather simple task (which more frustrating ;-) ): have column this:

>foo111_bar37 >foo111_bar38 >foo111_bar40 >foo111_bar40 >foo111_bar41 >foo111_bar42 >foo111_bar49 >foo111_bar49 >foo111_bar49 ... 

and either modify column or new column, includes current count of same string

>foo111_bar37x1 >foo111_bar38x1 >foo111_bar40x1 >foo111_bar40x2 >foo111_bar41x1 >foo111_bar42x1 >foo111_bar49x1 >foo111_bar49x2 >foo111_bar49x3 ... 

goal line becomes unique , still contains original information. found out how adress column awk , change strings in general (e.g. appending "x1"), not how number-specific changes. people seem want rid of duplicates or count total number of duplicates, not helping me here.

btw: i'm using mobaxterm bash environment on windows

thanks lot!

using awk, have available:

$ awk '{a[$1]++;print $1 "x" a[$1]}' file >foo111_bar37x1 >foo111_bar38x1 >foo111_bar40x1 >foo111_bar40x2 >foo111_bar41x1 >foo111_bar42x1 >foo111_bar49x1 >foo111_bar49x2 >foo111_bar49x3 

explained:

$ awk ' {    a[$1]++             # store hash using first field key. ++ increases                        # value 1 on each iteration each $1    print $1 "x" a[$1]  # output $1, "x" , current value of a[$1] }' file 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -