awk script question

Shawn Tayler stayler
Tue Sep 7 20:52:40 PDT 2004


ooo  Thanks Kurt!

BTW, is there a way to get awk to conditionally grab a field from the next
line?  As an example, each of the lines I am outputing these fields from
contains the word Unit.  I would like to grab one of the field from the
line immediatly follwing the line used for the fields here.  Any
suggestions?

Shawn

On Tue, 7 Sep 2004 15:24:20 -0400 Kurt Wall <kwall at kurtwerks.com>
exclaimed:

> 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
> _______________________________________________
> Linux-users mailing list
> Linux-users at linux-sxs.org
> http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users
> 


More information about the Linux-users mailing list