![]() |
|
|||||||
| Home | Forums | Register | Rules & FAQ | Donate | Members List | 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. |
![]() |
|
|
Submit Tools | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 : 1 Week Ago at 07:11 AM. |
| Forum Sponsor |
|
|
|
|||
|
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. |
|
||||
|
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
|
|
||||
|
Here goes another unconventional way of passing variables to awk:
Code:
echo "Enter month: "
read MONTH
awk '/'$MONTH'/ { print ... }' file
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 : 5 Days Ago at 04:21 PM. Reason: last sentence |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Proxy ARP Difficulties | TheMaskedMan | IP Networking | 7 | 11-02-2005 08:14 AM |
| Simple Network Program Difficulties | Mistwolf | High Level Programming | 2 | 03-19-2002 04:34 AM |