Hi,
when i use the following awk i will get the output like double time printed values and the 2nd time only its giving data,
please help me to find this
for ex: awk code:
file_name=$1
file_name1=$2
ctn=$(awk 'FNR==NR{a[$2]=$4;}$2 in a{t=a[$2]-$4;print $2,(FNR==1)?"":t"@"}' ${file_name} ${file_name1})
echo $ctn > result.tsv
sed -i 's|@|\n|g' result.tsv
sed -i 's|^ ||g' result.tsv
file.tsv
10787 10026700 sb 267.00 228.88
11485 10056416 sb 22.61 0
11416 10073755 sb 29.23 0
10879 10098634 sb 58.99 0
10674 10153713 sb 99.88 0
11462 10216854 sb 44.97 0
10793 10233900 sb 0 0
11504 10251332 sb 69.98 0
10890 10295983 sb 39.97 0
10881 10335174 sb 69.96 0
11531 10339632 sb 65.00 0
11532 10339655 sb 115.00 0
11533 10339656 sb 145.00 0
10753 10339974 sb 199.98 0
10547 10543801 sb 19.97 0
10894 10598332 sb 224.54 0
10694 10629144 sb 279.00 0
11438 10629145 sb 500.00 0
10899 10669752 sb 219.00 199.00
file1.tsv
10787 10026700 sa 267.00 228.88
11485 10056416 sa 22.61 0
11416 10073755 sa 29.74 0
10879 10098634 sa 58.99 0
10674 10153713 sa 99.88 0
11462 10216854 sa 44.97 0
10793 10233900 sa 0 0
11504 10251332 sa 0 0
10890 10295983 sa 39.97 0
10881 10335174 sa 69.96 0
result.tsv
10026700 10056416 0
10073755 0
10098634 0
10153713 0
10216854 0
10233900 0
10251332 0
10295983 0
10335174 0
10339632 0
10339655 0
10339656 0
10339974 0
10543801 0
10598332 0
10629144 0
10629145 0
10669752 0
10026700 10056416 0
10073755 -0.51
10098634 0
10153713 0
10216854 0
10233900 0
10251332 69.98
10295983 0
10335174 0
---------- Post updated at 04:50 PM ---------- Previous update was at 04:46 PM ----------
it should print the 2nd col value with the result value which is 4th col. Comparison (if it find 10056416 in file1.tsv then sub the 22.61 - 22.61 print the 0 value)