SUMMARY: OT: awk question

From: Barry Deevey <Barry.Deevey_at_sefas.co.uk>
Date: Thu Dec 13 2001 - 05:15:23 EST
Hello everybody,

Thank you to everybody that responded, there were too many to list but you
know who you are!!

I had numerous replies, a lot of people stated that I should use nawk with
the -v option, which allows you to define the variable before you start
using it.  I was also informed that my awk command string was in single
quotes, and variable substitution is not performed within single quotes....

Here's a few examples that people provided for me:

#	java_jjc_var=`cat $PS_TMP | awk "\$3 ~ /$var1/ {print
\$2}"`var1=$jjc_var
Note that you will have to escape the "$" that are in the command now.

#	First, the cat is not necessary; just use:
	awk '/.../{whatever}' $PS_TMP

#	cat $PS_TMP | nawk -v dev=$jjc_var '$3 ~ dev {print $2}' 

Thanks again for your help, its much appreciated.

Cheers,
Barry.

> To:	'sunmanagers@sunmanagers.org'
> Subject:	OT: awk question
> 
> Hi all,
> 
> I have the following code in a script I am writing:
> 
> java_jjc_var=`cat $PS_TMP | awk '$3 ~ /pattern_to_be_matched/ {print $2}'`
> 
> The above works fine when the pattern_to_be_matched is manually typed, but
> I
> cannot get it to read a variable from the script, i.e.
> 
> jjc_var=something
> 
> java_jjc_var=`cat $PS_TMP | awk '$3 ~ /var1/ {print $2}'`var1=$jjc_var
> 
> I apologise if I'm doing something stupid, but I'm not ver familiar with
> awk
> and its starting to drive me crazy!
> 
> TIA for any responses, they're greatly appreciated.
> 
> Best Regards,
> 
> Barry
> _______________________________________________
> sunmanagers mailing list
> sunmanagers@sunmanagers.org
> http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Thu Dec 13 10:15:23 2001

This archive was generated by hypermail 2.1.8 : Wed Mar 23 2016 - 16:32:37 EDT