I want to subtract the values from two columns and add result into a new column (at the very end) using awk or bash. the data is in a txt file.
I tried
awk 'BEGIN {OFS="\t"} NR == 1 {$20 = "tr_pe"} NR >=2 {$20= $5-$11}1' <filename
or
awk OFS="\t" \{$(NF+1)=$5-$11}1' filename.txt
The first code did the subtraction but saved it in column 2 instead of at the end, and I realised that it actually did not get saved to the txt.file. Second one did some calculation but it was not accurate
What I want to do - subtract values from column 5 with column 11 and save it under header tr_pre (which falls into column 20 at the end of all the 19 columns in the file). Columns are separated by tab.