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

AWK command to find 2 values in a f

Reply to Message Icon

Original Message
Name: warburp
Date: December 15, 2003 at 08:48:12 Pacific
Subject: AWK command to find 2 values in a f
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


Report Offensive Message For Removal


Response Number 1
Name: Finnbarr P. Murphy
Date: December 16, 2003 at 13:08:19 Pacific
Subject: AWK command to find 2 values in a f
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: AWK command to find 2 values in a f

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge