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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SED Search Pattern and Replace with the Pattern racbern Shell Programming and Scripting 4 03-15-2008 05:59 AM
Perl onliner to search the last line with an occurence of a pattern ammu Shell Programming and Scripting 4 01-31-2008 01:09 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Search for a pattern from the result of search boopathi_d Shell Programming and Scripting 3 12-05-2007 09:54 AM
Search file for pattern and grab some lines before pattern frustrated1 Shell Programming and Scripting 2 12-22-2005 03:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-29-2008
openspark openspark is offline
Registered User
  
 

Join Date: Aug 2008
Location: New Jersey
Posts: 22
Smile Perl Search pattern error

Hi,

  1. I am trying to grep for two patterns from a set of 820 apache webserver logs,
  2. When I Try to search the pattern with a date stamp and use a wildcard character * for ex: /28/Aug/2008:21*/ to get all the log entries for that particular hour that is 21 st hour I get errors. Please kindly let me know where I am going wrong.

The following is the command I am trying to use:

perl -ne 'print if (/mckinskey@futuron.com/ ? ($c=1) : (--$c > 0)) ; print if (/28/Aug/2008:21*/ ? ($d = 1) : (--$d > 0))' request.log*



[m78i5@serv125 ~]$ perl -ne 'print if (/mckinskey@futuron.com/ ? ($c=1) : (--$c > 0)) ; print if (/28/Aug/2008:01:35*/ ? ($d = 1) : (--$d > 0))' request.log*
Bareword found where operator expected at -e line 1, near "/28/Aug"
(Missing operator before Aug?)
syntax error at -e line 1, near "/28/Aug"
Search pattern not terminated at -e line 1.

[m78i5@serv125 ~]$ perl -ne 'print if (/mckinskey@futuron.com/ ? ($c=1) : (--$c > 0)) ; print if (/28/Aug/2008:01*/ ? ($d = 1) : (--$d > 0))' request.log*
Bareword found where operator expected at -e line 1, near "/28/Aug"
(Missing operator before Aug?)
syntax error at -e line 1, near "/28/Aug"
Search pattern not terminated at -e line 1.

[m78i5@serv125 ~]$ perl -ne 'print if (/mckinskey@futuron.com/ ? ($c=1) : (--$c > 0)) ; print if (/28/Aug/2008:21*/ ? ($d = 1) : (--$d > 0))' request.log*
Bareword found where operator expected at -e line 1, near "/28/Aug"
(Missing operator before Aug?)
syntax error at -e line 1, near "/28/Aug"
Search pattern not terminated at -e line 1.



Thanks

Last edited by openspark; 08-29-2008 at 12:54 PM.. Reason: Had to change a character and add additional information,
  #2 (permalink)  
Old 09-02-2008
bwreed bwreed is offline
Registered User
  
 

Join Date: Mar 2002
Location: Saint Paul, MN
Posts: 6
The / is being treated as the search term delimiter. Put double-quotes around the date string. Also, you don't need the *. In /28/Aug/2008:21* that really means /28/Aug/2008:2 and zero or more ones. Depending on how strict you want the match, you could use this:
print if ( m"/28/Aug/2008:21" ...
But I think you have other issues in your command.

I find that complex one-liners like this are better done first as a multi-line perl script file. Get it working, then compress it down to one line, then use it with perl -e.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0