[comp.unix.questions] awk >> operator

jew@charon.sunquest.com (James E. Ward) (03/14/91)

I would like to break a file into smaller files based on lines in the text.
I can get the filename I want into a variable, but can't seem to get the
awk syntax right to redirect print output into the file contained in the
variable.  Here's an example script.  Can anyone show me the proper syntax?

awk '{
	if ($0 ~ "^IXXPS2-") Output=$1
	print >> Output
}'

Thanks in advance,

James

jew@charon.sunquest.com (James E. Ward) (03/14/91)

I figured it out last night.  The problem was that the first line of the
input file did not define the Output variable, so awk didn't know where
to send it's output.  Thanks if you tried to help!

Final Program:


#!/bin/sh
#
#
awk 'BEGIN {
	Output="/dev/null"
}
{
	if ($0 ~ "^IXXPS2-") Output=$1
	print >>Output
}'