Input
10 8 20 8 10 9 20 9
10 12 20 19 10 10 20 40
Output1
10 8 2 20 8 12 10 9 1 20 9 11
10 12 -2 20 19 1 10 10 0 20 40 -20
Output2
10 9 1
20 40 -20
First I would like to take the difference of the 1st column and second column and print as 3rd column (10-8=2) and same follows to the 3&4, 5&6, 7&8 columns.
I assume this is the code that can print the output1
awk '{print $1,$2,$1-$2,$3,$4,$3-$4,$5,$6,$5-$6,$7,$8,$7-$8}' Input
Second I would like to compare the values (the new columns like 3rd(the value of $1-$2) and 6th($3-$4),9($5-$6)th and 12th ($7-$8)) of the 4 fields (2 \t 12 \t 1 \t 11) and print the the set with minimum difference
For example the first minimum value in 1st row is 1 (i.e.10-9). So it has to be in output2 and second minimum value in 2nd row is -20 (20-40). So it has to be in output2.
I think I explained little bit broadly to understand easily.
Thanx
---------- Post updated at 10:34 PM ---------- Previous update was at 07:27 PM ----------
I solved it Thanx
This is for output1
awk '{print $1,$2,$1-$2,$3,$4,$3-$4,$5,$6,$5-$6,$7,$8,$7-$8}' Input.txt
This is for output2
awk '{if($3<$6 && $3<$9 && $3<$12) {print$1,$2,$3} if($6<$3 && $6<$9 && $6<$1
2) {print $4,$5,$6} if($9<$3 && $9<$6 && $9<$12) {print $7,$8,$9} if {print $12<$3 && $12<$6 && $12<$9) {print
10,$11,$12}}' Output1.txt