hi I would like to sort rows in a givin file except the first colomn (or first element of a row) just like the following example
file input :
1 3 8 5
2 2 8 1
3 9 8 10
file output :
1 8 5 3
2 8 2 1
3 10 9 8
thanks in advance
hi I would like to sort rows in a givin file except the first colomn (or first element of a row) just like the following example
file input :
1 3 8 5
2 2 8 1
3 9 8 10
file output :
1 8 5 3
2 8 2 1
3 10 9 8
thanks in advance
perl -ne '@x=split/\s+/,$_; print shift @x; print " "; @x=reverse sort{$a<=>$b}@x; print "@x\n"' input.txt;
output:
1 8 5 3
2 8 2 1
3 10 9 8
Try...
while read a b; do printf '%s ' $a; echo $b | tr ' ' '\n' | sort -nr | paste -s -d ' '; done < file1
thanks a loooooooot
---------- Post updated at 12:32 AM ---------- Previous update was at 12:09 AM ----------
thanks ygor
last thing
if I want to store the first ans second column in a file, first and 3th column in a second file ans finally first and 4th column in a 3th file how can i do this
Not really a one-liner anymore. Same code as before, but with a tee to awk...
while read a b
do
printf '%s ' $a
echo $b | tr ' ' '\n' | sort -nr | paste -s -d ' '
done < file1 | tee outfile1 |\
awk '{for(x=2;x<=NF;x++) print $1, $x > "outfile" x}'
Which gives...
==> outfile1 <==
1 8 5 3
2 8 2 1
3 10 9 8
==> outfile2 <==
1 8
2 8
3 10
==> outfile3 <==
1 5
2 2
3 9
==> outfile4 <==
1 3
2 1
3 8