The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Proxy ARP Difficulties TheMaskedMan IP Networking 7 11-02-2005 06:14 AM
Simple Network Program Difficulties Mistwolf High Level Programming 2 03-19-2002 02:34 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 05-11-2008
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Stumble this Post!
Admitted that rubin's way is much more clearer and readable, you can pass variables also interrupting and resuming the awk code by the means of single quotes, like I posted before.

The problem is that before I made a mistake, you also need to add a couple of double quotes to complicate things a little bit more

Code:
awk '$3=="'"$MONTH"'" {print $1, $2, $3, $4, $5, $6}' *.hits
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 05-11-2008
rubin's Avatar
Registered User
 

Join Date: Nov 2007
Posts: 174
Stumble this Post!
Here goes another unconventional way of passing variables to awk:

Code:
echo "Enter month: "

read MONTH

awk '/'$MONTH'/ { print ... }' file
Caveat emptor:
The above approach does not work if the variable has whitespaces, newlines or certain special characters ( |, /, ...) in it.
So it's always recommended using the conventional way -v var=... .

Last edited by rubin; 05-11-2008 at 02:21 PM. Reason: last sentence
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0