> I have tried your suggestion with a slight modification:
> #!/bin/ksh
> awk '/^Feature/ && match($2,"^[0-9]+$") {
> getline num
> if (match(num,"^[0-9]+$")) {
> echo " $2 num "
> }
> }' $1
> This doesn't work. I get the following error message:
> awk: syntax error near line 1
> awk: bailing out near line 1
You must be using an old version of awk. Instead of awk, use nawk, gawk
or mawk.
With nawk, you might still get a complaint about the "&&", in which case
move the test for the number inside the braces:
nawk '/^Feature/ { if (match($2,"^[0-9]+$")) {
### etc....
}
}' $1
> Emm
> > > Thank you for your input. This is my shot at it.
> > > cat $1 | while read I; do
> > > TMP=`echo $I|awk '$1 ~ /Feature/ { print $2 }'`
> > > LIC=`echo $I|awk 'NF==1 && $1 ~ /^[0-9]/ { print $1 }'`
> > > if [ "$TMP" != "" ]; then
> > > FTRE=$TMP
> > > elif [ "$LIC" != "" ]; then
> > > ./inst.tcl $FTRE $LIC
> > > fi
> > > done
> > > The file that I parse will have some arbitrary content on the top that
> I'm
> > > not interested in. I'm only interested in line pairs that look like
> this:
> > > Feature [number]
> > > [one long field starting with numbers]
> > > Feature [number]
> > > [one long field starting with numbers]
> > > Feature [number]
> > > [one long field starting with numbers]
> > > Feature [number]
> > > [one long field starting with numbers]
> > > This line pair combination is reapeated and I want to extract the
> feature
> > > number and the number on next line and pass it to an expect script as
> $argv0
> > > and $argv1. The above code works, but I'm not going to argue its
> elegance.
> > Doing the whole thing in awk will result in a much faster and more
> > efficient script:
> > awk '
> > ## Match only lines beginning with "Feature"
> > ## and whose second field is a number
> > /^Feature/ && match($2,"^[0-9]+$") {
> > ## get the next line
> > getline num
> > ## if it is a number...
> > if (match(num,"^[0-9]+$")) {
> > ## create a command with the two numbers
> > cmd = "./inst.tcl " $2 " " num
> > ## execute the command
> > system(cmd)
> > }
> > }' $1
> > > Emm
> > > > > Why doesn't this work:
> > > > > #!/bin/ksh
> > > > > for I in $(cat $1); do
> > > > > if [ `echo $I | awk '{$1 ~ /Feature/}'` ]; then
> > > > > FEATURE=echo $I | awk '{ print $2 }'
> > > > > echo $FEATURE
> > > > > fi
> > > > > done
> > > > > What I'm trying to do is to read the second field from each line of
> the
> > > file
> > > > > specified on the command line ($1)that contains the string
> "Feature". I
> > > > > have a file with multiple lines, some lines beginning with "Feature"
> I
> > > want
> > > > > to retrieve the field following Feature.
> > > > It's a one-liner:
> > > > awk '/^Feature/ {print $2}' $1
> > --
> > Chris F.A. Johnson http://cfaj.freeshell.org
> > ===================================================================
> > My code (if any) in this post is copyright 2001, Chris F.A. Johnson
> > and may be copied under the terms of the GNU General Public License
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2001, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License