The UNIX and Linux Forums  

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


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
421 service not available, remote server has closed connection ^m automate ftp autosys awk trim bash eval bash for loop boot: cannot open kernel/sparcv9/unix command copy/move folder in unix couldn't set locale correctly curses.h cut command in unix find grep find mtime find null character in a unix file grep multiple lines grep or grep recursive gzip password hp-ux ifconfig inaddr_any inappropriate ioctl for device lynx javascript mailx attachment mget mtime perl array length ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude tar extract to folder test: argument expected unix unix .profile unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi substitute while loop within while loop shell script

View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 05-09-2008
rubin's Avatar
rubin rubin is offline
Registered User
 

Join Date: Nov 2007
Posts: 134
You need to use AWK's special way of passing variables into it:

Code:
echo "Enter month: "

read MONTH

awk -v mon="$MONTH"  '$3~mon { print $1, $2, $3, $4, $5, $6}' *.hits
Or equally:

Code:
awk '$3~mon { print $1, $2, $3, $4, $5, $6}'  mon="$MONTH" *.hits
Same thing if year is also needed:

Code:
awk -v mon="$MONTH" -v year="$YEAR" '$3~mon && $6~year { print ... } *.hits
Reply With Quote