Perl Search pattern error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Search pattern error
# 1  
Old 08-29-2008
Bug 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  
Old 09-02-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. UNIX for Beginners Questions & Answers

Using forward slash in search pattern in perl script

I have existing pattern in the perl script as: my $pattern = "^Line.*?:|^Errors*: |^SEVERE:.*?:|^Null pointer exception occurred"; and I wanted to include below keywords in my search pattern "I/O exception" and "FileNotFoundException"the problem is when I include my pattern like my... (5 Replies)
Discussion started by: ambarginni
5 Replies

3. Shell Programming and Scripting

Help need with PERL multiple search pattern matching!

My example file is as given below: conn=1 uid=oracle conn=2 uid=db2 conn=3 uid=oracle conn=4 uid=hash conn=5 uid=skher conn=6 uid=oracle conn=7 uid=mpalkar conn=8 uid=anarke conn=9 uid=oracle conn=1 op=-1 msgId=-1 - fd=104 slot=104 LDAPS connection from 10.10.5.6 to 10.18.6.5 conn=2... (3 Replies)
Discussion started by: sags007_99
3 Replies

4. Shell Programming and Scripting

perl script to search n place a pattern

hi, i have one file as t1.txt as below hi hello welcome i want perl script to search for the pattern "abcd" in the file. if the pattern doesn't exist, i want to insert that pattern at the end of the same file t1.txt my o/p should be hi hllo welcome abcd thank you (3 Replies)
Discussion started by: roopa
3 Replies

5. Shell Programming and Scripting

Multiple pattern search in perl

user 10 values content is: musage.py yes value user 11 values content is: gusage.py yes value how to print "user" string line by searching "content is:" string and "usage.py" string in perl (8 Replies)
Discussion started by: Anjan1
8 Replies

6. Shell Programming and Scripting

search more than one pattern with perl on same line

Hi friends, I want to search for some hex error codes in some files. After the hex error code is found, the occurences would be counted. Afterwards the found hex errorcode would be cat into a separate file. Here is my code: #!/usr/bin/perl use File::Basename; my $find = $ARGV; my... (2 Replies)
Discussion started by: sdohn
2 Replies

7. Shell Programming and Scripting

perl pattern search

can someone help me out with the bolded? else if (regmatch($Subject, "^Application") && (regmatch($From, "^etgh") && (regmatch($Body, ".*not authorized to use this server.*")))) what this section of the code is suppose to do is to scan through the contents of $Body, if do a set of... (1 Reply)
Discussion started by: SkySmart
1 Replies

8. Shell Programming and Scripting

perl:: search for tow pattern and replace the third pattern

Hi i want to search two pattern on same line and replace onther pattern.. INPut file aaaa bbbbb nnnnnn ttttt cccc bbbbb nnnnnn ppppp dddd ccccc nnnnnn ttttt ffff bbbbb oooooo ttttt now i want replace this matrix like.. i want search for "bbbbb","nnnnnn" and search and replace for... (4 Replies)
Discussion started by: nitindreamz
4 Replies

9. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies

10. Shell Programming and Scripting

Perl onliner to search the last line with an occurence of a pattern

Hi I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it. similar to grep 'pattern' filename | tail -1 in UNIX Ex: I want to display the line starting with "cool" and which is a last occurence adadfadafadf adfadadf cool dfadfadfadfara... (4 Replies)
Discussion started by: ammu
4 Replies
Login or Register to Ask a Question