[HPADM] SUMMAY: AWK Question

From: Bill Beardshaw (BBeardshaw@gfd.com)
Date: Fri Feb 16 2007 - 16:30:13 EST


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@gfd.com
(336) 316-4006

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:55 EDT