Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How do I subtract column #2 in one file from column #2 in another file and then print column #1 and the result of the subtraction into a third file?
Thanks a lot!

Try the below, redirecting the output to a third file:
file1
AA 10
AA 10
AA 10File2
BB 50
BB 40
BB 30
$ nawk 'FNR==NR {arr[NR]=$2; next} { print $2-arr[FNR]}' file1 file2
40
30
20

Should work for whichever flavor of awk you use;
gawk -F'field separator eg space' '{print $2 - $1}' filename > newfile

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |