[HPADM] SUMMAY: AWK Question
- From: "Bill Beardshaw" <BBeardshaw@xxxxxxx>
- Date: Fri, 16 Feb 2007 16:30:13 -0500
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
- Prev by Date: [HPADM] AWK Question
- Next by Date: [HPADM] Sshell history across nfs
- Previous by thread: [HPADM] AWK Question
- Next by thread: [HPADM] Sshell history across nfs
- Index(es):
Relevant Pages
|
|