nawk add column to each line

748 Views Asked by At

I am trying to add column with the name of the file into the end of each line. Every line has a

Name Surname   some_number

Name and surname are separated with space and number is separated from Surname by tab.

I am doing it with this script but it does not work, it only adds filename to start of the line.

$1=temp
nawk -v F'\t' -v OFS='\t' '{$2=$2" "$temp} 1' $temp

PS OS is SunOS.

2

There are 2 best solutions below

4
On

Try with:

awk '{ printf( "%s %s\n", $0, FILENAME ); }' infile
0
On

awk '{print $0, FILENAME}' file