I have bash script looping through several files in a directory. The file identifier has been saved as a variable $num. What I would like to do is add $num as another column in my data like in the example below:ORIGINAL INPUT:A B C D E2 79 56 SD L1 09 67 JK S9 60 37 KD G0 10 47 SO EEXPECTED OUTPUT:A B C D E id2 79 56 SD L 11 09 67 JK S 19 60 37 KD G 10 10 47 SO E 1*in above example, $num = 1Ultimately, I want to take a subset of lines from each looped file and cat them into a single large file. For me to know which file the line came from, I need the id from $num.I have tried using awk '{$12 = $num}' filename but this does not work at all.Please help!
bash: how to add assigned value to file
bash;awk;loop device
try (awk can be in one line) id=... awk -v id=$id 'NR==1 { x=NF+1 ; $x = id ; print ; }                NR > 1 { x=NF+1 ; $x = id ; print ; } ' file > new_filewhere -v id=$id  paste id from shell to awk, if id has funny char, use -v id=dNR == 1 , NR  > 1 select first, other line{ x=NF+1 ; $x = id ; print ; } push $id ( id in awk )