Reputation: 133
Below contents are stored in an file. & i wish to use AWK for the desired output... (or a sample shell script).
Original Content.
A 193
A 27
B 82
B 496
C 117
D 251
D 3
E 26
E 151.... and so on.
I need the above contents to be Numbered in an Interative Fashion w.r.t to its Individual Instance.
i.e. output should be
A_1=27
A_2=193
B_1=82
B_2=496
C_1=117
D_1=251
D_2=3
E_1=26
E_2=151.....
Upvotes: 1
Views: 37
Reputation: 369044
Using awk
:
$ cat test.txt
A 193
A 27
B 82
B 496
C 117
D 251
D 3
E 26
E 151
$ awk '{printf("%s_%d=%s\n", $1, ++num[$1], $2)}' test.txt
A_1=193
A_2=27
B_1=82
B_2=496
C_1=117
D_1=251
D_2=3
E_1=26
E_2=151
Upvotes: 3