Setting Multiple Shell Variables from One Run of awk



Right now, I have a shell script that does the following:

hostname=`echo $NEWDEV |awk 'BEGIN{FS="."}{print $1}'`
domain=`echo $NEWDEV |awk 'BEGIN{FS="."}{print $2}'`
top0=`echo $NEWDEV |awk 'BEGIN{FS="."}{print $3}'`
top1=`echo $NEWDEV |awk 'BEGIN{FS="."}{print $4}'`

That looks inefficient (dumb) so I ask, is there a way
to assign the fields in an awk expression to shell variables as
one runs awk once?

Being able to do that would mean one run of awk instead
of the 4 shown here and, if file accesses are involved, there is
only one of those.

Thanks.

Martin McCormick WB5AGZ Stillwater, OK
Systems Engineer
OSU Information Technology Department Telecommunications Services Group


--
To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx
with a subject of "unsubscribe". Trouble? Contact listmaster@xxxxxxxxxxxxxxxx



Relevant Pages

  • Re: Setting Multiple Shell Variables from One Run of awk
    ... to assign the fields in an awk expression to shell variables as ... shell array with several values in one operation. ... shell script to set the variables, maybe you could then source that ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: awk and date command
    ... awk -v DT=`date +%Y%m%d` program.awk record.txt ... Country: Australia ... Text or chat with friends inside Yahoo! ... To unsubscribe: ...
    (Fedora)
  • Re: awk and date command
    ... but i don't know how to put the hostname in awk ... Text or chat with friends inside Yahoo! ... To unsubscribe: ...
    (Fedora)
  • Re: awk and date command
    ... Use a printf statement as follows: ... P.S. Awk! ... Text or chat with friends inside Yahoo! ... To unsubscribe: ...
    (Fedora)
  • Re: piped to awk: how to print vars outside of line-in loop
    ... I have been tinkering with a shell script that takes the output from a ... program and pipes it to awk to extract certain items and format them ... print "Encoder is: " Encoder ... print "Container is:" Container ...
    (comp.unix.shell)