Can I print the minimum and maximum values of values in first 4 columns ?
input
3038669 3038743 3037800 3038400 m101c
3218627 3218709 3217600 3219800 m290
.............
output
3037800 3038743 m101c
3217600 3219800 m290
Can I print the minimum and maximum values of values in first 4 columns ?
input
3038669 3038743 3037800 3038400 m101c
3218627 3218709 3217600 3219800 m290
.............
output
3037800 3038743 m101c
3217600 3219800 m290
Hi
A perl solution:
$ perl -alne '$,=" ";use List::Util qw(max min);$x=pop @F;print max(@F),min(@F),$x;' file
3038743 3037800 m101c
3219800 3217600 m290
Guru.
---------- Post updated at 06:30 AM ---------- Previous update was at 06:08 AM ----------
Using awk: (just realized you tagged as awk)
$ awk '{min=$1;for(i=1;i<=4;i++){if ($i>max)max=$i; if ($i<min)min=$i;} print max,min,$NF;}' file
3038743 3037800 m101c
3219800 3217600 m290
Guru.
max would need to be reset too:
awk '{min=max=$1; for(i=2;i<=4;i++){if($i<min) min=$i; if($i>max) max=$i} print min,max,$5}' file