columns

Arnold D. Robbins arnold at infographix.infographix.com
Wed Feb 21 14:26:45 EST 1996


> From: <jnm at safn2.saf.com>
> Subject: columns
> Date: Wed, 21 Feb 96 13:11:48 EST
>
> Does anyone know an easy way to cause a list of fields to be
> converted to a column of fields?
>
> eg. take the file with '|' as the field seperator:
>
> every | good | boy | does | fine
>
> and you want it to be:
>
> every
> good
> boy
> does
> fine
>
> I have tried using sed to no avail. I could write a short c program
> but this seems overkill. I am hoping there is some quick linux trick
> to accomplish this. Thanks!

Use gawk:

	gawk 'BEGIN { FS = "[ \t]*\\|[ \t]*" }
	      { for (i = 1; i <= NF; i++)
			print $i
	      }' < datafile

This uses zero or more spaces or tabs, a pipe, and zero or more spaces or
tabs as the field separator regular expression.

See ftp://ftp.gnu.ai.mit.edu/pub/gnu/gawk-3.0.0.tar.gz for source and
full documentation. (This is new enough that I expect most Linux
distributions don't have it yet, although it should work in whatever
gawk you have now.)

And yes, I know it can be done in perl, and no, I don't care to be shown
how to do it or to start a flame war on the subject. Those who know who I
am know why. (:-)

Arnold Robbins		InfoGraphix (Star Imaging LLC, dba)
Phone: +1-404-523-4944	250 Williams Street, Suite 1120, Atlanta, GA 30303
Fax:   +1-404-523-4882	E-mail: arnold.robbins at infographix.com
"Oh! Look at all those zeros!" --- Chana Robbins, Age 3.5






More information about the Ale mailing list