Operating System - HP-UX
1759410 Members
3166 Online
108882 Solutions
New Discussion юеВ

awk,,, examine columns from right to left

 
SOLVED
Go to solution
Kirk Reindl
Frequent Advisor

awk,,, examine columns from right to left

Hi,

Is there an argument/switch in awk that will examine columns from "right to left" as opposed to the default which is "left to right"??

Thanks

Kirk Reindl
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor
Solution

Re: awk,,, examine columns from right to left

Hi Kirk:

No, but its easy to do. Consider, for any number of fields on any line:

# echo "1 2 3"|awk '{for (i=NF;i>=1;i--) print $i}'

Regards!

...JRF...
Tim D Fulford
Honored Contributor

Re: awk,,, examine columns from right to left

If you have a multiple row file JRF's might not put in the caridge return after each line...

awk '{for(i=NF;i=2;i=i-1) printf "%s ", $i; printf "%s\n", $1}'

Otherwise, as always, JRF is on the money

Regards

Tim
-
Tim D Fulford
Honored Contributor

Re: awk,,, examine columns from right to left

oops, one slight correction

awk '{for(i=NF;i>1;i=i-1) printf "%s ", $i; printf "%s\n", $1}'
-