columns

Mark J. Reed mark.reed at sware.com
Wed Feb 21 14:18:58 EST 1996


<jnm at safn2.saf.com> writes:
\ 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

Well, if you want that conversion, then the field separator isn't '|'
but " | ".  Getting rid of the extra whitespace is the tricky part.
Pick your tool:


sed (strips whitespace - note that part of the command is on the second line):
	sed -e 's/[ 	]*\|[ 	]*/\
/g'

awk (doesn't strip whitespace):
	awk -F\| '{for (i=0; i<=NF; ++i) {printf "%s\n", $i}}' 

perl (strips whitespace):
	perl -pe '$_ = join("\n",split(/\s*\|\s*/));'






More information about the Ale mailing list