Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm trying to use AWK to find a line in a file equal to 2 different variables and write it to another variable. I can find the values individually but I can't work out how to put them together. Here are the lines:
e=`awk '/ALMHT?/' $DIRLOG$CFILE`
f=`awk '$2 == "Active"' $DIRLOG$CFILE`
Thanks

Here is one way of doing it. This works
on Tru64 UNIX 5.1B but should work on
most other Unices.- Pass in the variables using the
-v command line option i.e.awk -v var1=$DIRLOG -v var2=$CFILE ...
Some versions of awk do not have a
-v option and instead will just acceptawk var1=$DIRLOG var2=$CFILE ...
Look at the manpage for your particular
verion of awk/nawk/gawk.- Output lines that match using syntax
similar to following:$0 ~ var1 && $0 ~ var2 {print $0}
Good luck- Finnbarr

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |