Operating System - HP-UX
1844417 Members
3194 Online
110233 Solutions
New Discussion

simple shell script question

 
SOLVED
Go to solution
wvsa
Regular Advisor

simple shell script question

Good afternoon all,

I need to create a script that pulls all lines that have entries on 08/Sep/2004, note the following example:

192.168.200.51 - - [08/Sep/2004:11:59:42 -0700] "GET /OA_MEDIA/xxwvus/istore/GCL

Attempted to use awk but could not get it to work.

Your input would be greatly appreciated


7 REPLIES 7
Rick Garland
Honored Contributor

Re: simple shell script question

How about using grep?

This will pull the lines that match the pattern.
Sundar_7
Honored Contributor

Re: simple shell script question

Yeah, grep will do

# grep "[08/Sep/2004:" inputfile
Learn What to do ,How to do and more importantly When to do ?
Sridhar Bhaskarla
Honored Contributor

Re: simple shell script question

Hi,

Did you want to make the day as the variable? then do something like this

DATE=$(date +%d/%b/%Y)
grep "[${DATE}:" logfile

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
wvsa
Regular Advisor

Re: simple shell script question

Gentlemen, note the following:

grep "[08/Sep/2004:" access_log
grep: [] imbalance.

Am I missing something? Trying to print all lines with the occurance of 08/Sep/2004.


Thank you for input.

Sundar_7
Honored Contributor
Solution

Re: simple shell script question

Sorry, you should escape "["

grep "\[08/Sep/2004:" inputfile
Learn What to do ,How to do and more importantly When to do ?
wvsa
Regular Advisor

Re: simple shell script question

The escape did the trick, THANKYOU!

RAC_1
Honored Contributor

Re: simple shell script question

You need--

grep "\[08\/Sep\/2004:" inputfile

Anil
There is no substitute to HARDWORK