[PLUG] Awkward Field Separators

wes plug at the-wes.com
Tue May 13 17:30:39 UTC 2008


On 5/13/08, Rich Shepard <rshepard at appl-ecosys.com> wrote:
>
> On Tue, 13 May 2008, wes wrote:
>
> > are the commas or spaces unique to field separators? I would probably
> just
> > fix the field separators that are wrong, and then grab the fields
> normally.
>
> wes,
>
>   Here's what I've tried, but it does not work as desired:
>
> BEGIN {FS = " "}
>       {print $1, $2, $3}
>       {FS = ","}
>       {print $4, "," $3, "," $2, "," $1}
>
>   If I add the 4th field to the first print statement, nothing's changed.
> The output of this version is totally messed up.
>
>   Any thoughts on the path to the proper approach?
>
> Thanks,
>
> Rich
>
> --
> Richard B. Shepard, Ph.D.
> |  Integrity            Credibility
> Applied Ecosystem Services, Inc.        |            Innovation
> <http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax:
> 503-667-8863


 I'm sort of simplistic when it comes to this stuff.

I would pipe the output to sed, then pipe the output of that to your awk
command.

[get data] | sed "s/ /,/" | awk [print your stuff in the order you want]

-wes



More information about the PLUG mailing list