Computing.Net > Forums > Unix > AWK command to find 2 values in a f

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

AWK command to find 2 values in a f

Reply to Message Icon

Name: warburp
Date: December 15, 2003 at 08:48:12 Pacific
OS: Solaris 8
CPU/Ram: Ultra Sparc III
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Finnbarr P. Murphy
Date: December 16, 2003 at 13:08:19 Pacific
Reply:

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 accept

awk 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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: AWK command to find 2 values in a f

find unwanted characters in file www.computing.net/answers/unix/find-unwanted-characters-in-file/7046.html

Need to convert the date in a SQUID www.computing.net/answers/unix/need-to-convert-the-date-in-a-squid/3877.html

To read the value of a variable www.computing.net/answers/unix/to-read-the-value-of-a-variable/5570.html