Mohammed Gh Mohammed Gh - 4 months ago 6
Linux Question

How to add the number of line at the end of line in linux

How to add the number of line at the end of the corresponding line into a file text in linux ?

I know this command, but it add the number of line at the beginning and not at the end !

nl -ba -s ', ' fileName.txt > fileName2.txt


e.g.

5,10,33
7,17,77


have to be

5,10,33,1
7,17,77,2

Answer

in awk:

awk '{print $0","NR;}' file

on my system:

$ cat file
1 2
3 4
5 6
7 8
$ awk '{print $0","NR;}' file
1 2,1
3 4,2
5 6,3
7 8,4