awk script question

Kurt Wall kwall
Tue Sep 7 15:29:07 PDT 2004


In a 2.3K blaze of typing glory, Shawn Tayler wrote:
> 
> The outoput is nothing, the input file is 2 pieces of data, separated by a
> comma.  Field 1 is an integer, field 2 a string.  I think I've go it
> though.  Just tried removing one > and moving the redirect into the
> brackets.  But any suggestions you have would be appreciated...

The redirect needs to be part of the expression, yes. If you want
the integer separated from the the string value, try:

{ printf "%d %s\n", $1, $2 >> file }

Thus:

BEGIN { FS = "," } # comma delimited fields
{ OFS = "," }
#{ printf $1 "," $3 }
$1 < 3000                  { printf "%d %s\n", $1, $2 >> "1"  }
$1 >= 4000  && $1 <= 11999 { printf "%d %s\n", $1, $2 >> "1"  }
$1 >= 3000  && $1 <= 3999  { printf "%d %s\n", $1, $2 >> "2"  }
$1 >= 6900  && $1 <= 6999  { printf "%d %s\n", $1, $2 >> "3"  }
$1 >= 12000 && $1 <= 12499 { printf "%d %s\n", $1, $2 >> "4"  }
[...]

Notice that I also added newlines, which you might not require.

Kurt
-- 
"Now this is a totally brain damaged algorithm.  Gag me with a
smurfette."
	-- P. Buhr, Computer Science 354


More information about the Linux-users mailing list