[HPADM] SUMMAY: AWK Question



Thanks for all of the helpful replies, This is what I ended up with and
it works :-)

awk '
$9==JB {print $1,$2,$4,$8,$3,"NO_OPOOL",$9,$10,$NF ;next}
$10==JB {print $1,$2,$5,$9,$3,$4,$10,$11,$NF ;next}
$4==DT {print $1,$2,$4,$8,$3,"NO_OPOOL NO_LIB NO_SLOT",$NF ;next}
$5==DT {print $1,$2,$5,$9,$3,$4,"NO_LIB NO_SLOT",$NF ;next}
' JB=$JBOX_NAME DT=$DEV_TYPE $OUT > $CATLIST

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Jon Fife wrote:

If you add "; continue" after the print statements it should skip the
rest of the tests for that line.

eg.
awk ' $9==JB {print $1" "$2" "$4" "$8" "$3" NO_OPOOL "$9" "$10" "$NF;
continue } \

HTH,

Jon
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++
Andrew Belville Wrote:
Why don't you put an '; exit' after the print command. This will cause
the awk script to quit after it finds the first match and prints it.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Jeff wrote:
If it's always the first of the two records you can pipe it through "|
head -1" before your redirect to $CATLIST. If it's always the second
record you can use tail instead of head.
If its something else that makes the record unique between the two you'd
need to put in a pipe through grep instead.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

David Totsch wrote:
Bill! Long time not see. It is good to know you are still out there
harassing HP-UX systems. :-) The statement "next" tells awk to skip
pattern matching and load the next record. So, your awk script becomes:
awk ' $9==JB {print $1" "$2" "$4" "$8" "$3" NO_OPOOL "$9" "$10"
"$NF;next}
$10==JB {print $1" "$2" "$5" "$9" "$3" "$4" "$10" "$11" "$NF;next}
$4==DT {print $1" "$2" "$4" "$8" "$3" NO_OPOOL NO_LIB NO_SLOT "$NF;next}

$5==DT {print $1" "$2" "$5" "$9" "$3" "$4" NO_LIB NO_SLOT "$NF;next}' \
JB=$JBOX_NAME DT=$DEV_TYPE $OUT > $CATLIST
Notice that I made it one call to awk.
BTW: you don't need the " " between fields. A comma in a simple print
makes sure that fields are separated by a single space ('print
$1,$2,"TEXT",$3' and 'print $1" "$2" TEXT "$3' are equivalent).
Enjoy,
-dlt-



Original Request:
In the following I only one to get ONE match and then continue with the
next input record. The statements are in the order I want to match but
I only want the first match. As written some lines will match two times
and two records are written to $CATLIST, I only want one record.

awk ' $9==JB {print $1" "$2" "$4" "$8" "$3" NO_OPOOL "$9" "$10" "$NF} \
awk $10==JB {print $1" "$2" "$5" "$9" "$3" "$4" "$10" "$11" "$NF} \
awk $4==DT {print $1" "$2" "$4" "$8" "$3" NO_OPOOL NO_LIB NO_SLOT
"$NF} \
awk $5==DT {print $1" "$2" "$5" "$9" "$3" "$4" NO_LIB NO_SLOT "$NF}'
\
JB=$JBOX_NAME DT=$DEV_TYPE $OUT > $CATLIST

Bill Beardshaw
Guilford Mills, Inc
bbeardshaw@xxxxxxx
(336) 316-4006



Relevant Pages

  • Re: Random list of filenames
    ... each group containing a random assortment of filenames. ... I've tried using awk with randand sranduntil my head was ready to ... f.puts(list[i * chunk, chunk].sort) ...
    (comp.unix.shell)
  • Re: Random list of filenames
    ... each group containing a random assortment of filenames. ... I've tried using awk with randand sranduntil my head was ready to ... in the form of a script preproc: ...
    (comp.unix.shell)
  • Re: How can I see content of lines 453555 until 453590 of text file?
    ... Carroll Grigsby wrote: ... but it's not in my head): ... tail can also be used ... awk is probably safer, ...
    (Fedora)
  • Re: Random list of filenames
    ... each group containing a random assortment of filenames. ... I've tried using awk with rand() and sranduntil my head was ready to ...
    (comp.unix.shell)
  • Re: Random list of filenames
    ... each group containing a random assortment of filenames. ... I've tried using awk with rand() and sranduntil my head was ready to explode. ... I'm obviously getting the syntax wrong somewhere, but seeing as how I know very little about awk, it's not surprising. ...
    (comp.unix.shell)