![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Proxy ARP Difficulties | TheMaskedMan | IP Networking | 7 | 11-02-2005 07:14 AM |
| Simple Network Program Difficulties | Mistwolf | High Level Programming | 2 | 03-19-2002 03:34 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
trying to cope with awk difficulties
Quote:
The data we are searching is populated in this way: ----IP---------DAY----MONTH----DATE--------TIME---------YEAR 12.3234.34-----Fri------Nov-------15-------18:05:14 GMT---2008 I want the user to be able to search for the data according to month and year. However, I cannot quite figure out how to do this. Above is the code i have and i can't understand what is wrong? If we try and put in the variable e.g Nov, it wont give us any results. It works only if instead of "$MONTH" we enter the month itself e.g Nov or Sep. Last edited by amatuer_lee_3; 05-09-2008 at 05:11 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
You need to add single quotes to pass inside awk the shell variable:
Code:
awk '$3=='"$MONTH"' {print $1, $2, $3, $4, $5, $6}' *.hits
|
|
#3
|
|||
|
|||
|
Quote:
Quote:
I'm a bit stumped. |
|
#4
|
|||
|
|||
|
You need to specify the delimiter used by your flat file in the awk statement..
May not be the case...ignore this Last edited by Shivdatta; 05-09-2008 at 06:05 AM. |
|
#5
|
||||
|
||||
|
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
Code:
awk '$3~mon { print $1, $2, $3, $4, $5, $6}' mon="$MONTH" *.hits
Code:
awk -v mon="$MONTH" -v year="$YEAR" '$3~mon && $6~year { print ... } *.hits
|
|
#6
|
|||
|
|||
|
thanks very much.
can you use AWK to search for unique IP's within this? so if the same IP logged on more than once it would list the one IP with all the hits? I already have the IP's in a populated file with the month and date. |
|
#7
|
||||
|
||||
|
Simply modify the given code:
Code:
echo "Enter month: "
read MONTH
echo "Enter ip: "
read IP
awk -v mon="$MONTH" -v ip="$IP" '$3~mon && $1~ip { print ... }' *.hits
|
||||
| Google The UNIX and Linux Forums |