[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cut - reorder fields
From: |
Bob Proulx |
Subject: |
Re: cut - reorder fields |
Date: |
Thu, 27 Sep 2007 16:29:00 -0600 |
User-agent: |
Mutt/1.5.9i |
James KEEFER wrote:
> As far as I can see, there is no way to re-order fields using cut.
That is correct. But other tools do this easily.
> It would be nice to be able to specify -f 3,2,1 and have the first
> three fields switched in their order. It would also be nice to
> repeat an input fields in the output, such as -f 1,1,1 repeating the
> first field three times.
I suggest using awk for this. It is a standard tool that will do
exactly what you are asking.
$ echo one two three four | awk '{print $3,$1,$2}'
three one two
$ echo one two three four | awk '{print $3,$2,$1,$2}'
three two one two
Using awk just seems perfectly fitted to these types of tasks.
Bob