0

My input for cat file

ABC   
DEF  
DEF   
ABC   
GHI   
GHI   
DEF

The output that I want is:

ABC_1 
DEF_2
DEF_3
ABC_4
GHI_5
GHI_6
DEF_7

I tried to use the loop to do it but it failed.

1
$ awk '{print $1 "_" ++c}' file
ABC_1
DEF_2
DEF_3
ABC_4
GHI_5
GHI_6
DEF_7
  • thank you,now I only knew that one is store the value inside the array to execute the code,one is did not . – heng960407 Sep 13 '16 at 6:22
1
awk '$0=$0"_"NR' # padding to meet minimum answer length

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.