![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk and regular expression | maskot | Shell Programming and Scripting | 4 | 05-22-2007 04:22 AM |
| Regular Expression problem | djkane | Shell Programming and Scripting | 5 | 06-21-2006 07:07 AM |
| Regular Expression Problem | netmaster | UNIX for Dummies Questions & Answers | 1 | 12-07-2005 06:34 PM |
| Complex Pipeline/Redirection/Regular Expression problem | netmaster | UNIX for Dummies Questions & Answers | 1 | 11-28-2005 09:55 PM |
| Regular Expression + Aritmetical Expression | Z0mby | Shell Programming and Scripting | 2 | 05-21-2002 07:59 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Regular Expression Problem
this is how my xyz.log file loooks like :-
[30/Dec/2008:12:03:07] info ( 816): CORE1116: Sun ONE Web Server 6.1SP5 B08/17/2005 22:09 [31/Dec/2008:12:03:08] info ( 817): CORE5076: Using [Java HotSpot(TM) Server VM, Version 1.5.0_11] from [Sun Microsystems Inc .] [01/Jan/2008:12:03:08] info ( 817): WEB0100: Loading web module in virtual server [http-google] at [/abc] [02/Jan/2008:12:03:08] info ( 817): WEB0100: Loading web module in virtual server [http-google] at [/abc] Code:
perl -MPOSIX -i.bak -ne 'BEGIN{
$d=strftime("%d%m%Y",localtime time-60*24*60*60);
@m{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)}=("01".."12")}
print if m"^(\d+)/(\w+)/(\d{4})"&& "$1$m{$2}$3" gt $d' xyz.log
Any info will be really appreciated. I am new to regular expression. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Perhaps unrelated, but you forgot to escape the forward-slashes in your date in the regex.
Shawn |
|
#3
|
|||
|
|||
|
Forward slashes missing where?
|
|
#4
|
|||
|
|||
|
Sorry, I didn't pay attention to the fact that you're using double-quotes to surround the regex instead of the standard forward-slashes.
Actually, the problem seems to lie with the date formatting. Code:
$ perl -MPOSIX -e 'print strftime("%d%m%Y",localtime time-60*24*60*60);'
01022008
ShawnMilo & Friends (looking over my shoulder preventing me from giving three wrong answers before we found this one.) |
|
#5
|
|||
|
|||
|
Well re formatiing the file is out of question. Its a log file which is created by a java program. So re formatting the log file is out of question. I modified my script :-
Code:
perl -MPOSIX -i.bak -ne 'BEGIN{
$d=strftime("%Y%m%d",localtime time-60*24*60*60);
@m{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)}=("01".."12")}
print if m"^(\d+)/(\w+)/(\d{4})"&& "$1$m{$2}$3" gt $d' xyz.log
[30/Dec/2008:12:03:07] info ( 816): CORE1116: Sun ONE Web Server 6.1SP5 B08/17/2005 22:09 [31/Dec/2008:12:03:08] info ( 817): CORE5076: Using [Java HotSpot(TM) Server VM, Version 1.5.0_11] from [Sun Microsystems Inc .] |
|
#6
|
|||
|
|||
|
I believe you have to change
Code:
print if m"^(\d+)/(\w+)/(\d{4})"&& "$1$m{$2}$3" gt $d' xyz.log
Code:
print if m"^(\d+)/(\w+)/(\d{4})"&& "$3$m{$2}$1" gt $d' xyz.log
Shawn |
|
#7
|
|||
|
|||
|
Yea thats what i thought at the first glance and i already tried that swapping 1 to 3 same result. It deletes everything from the file.
Code:
perl -MPOSIX -i -ne 'BEGIN{
$d=strftime("%Y%m%d",localtime time-60*24*60*60);
@m{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)}=("01".."12")}
print if m"^(\d+)/(\w+)/(\d{4})"&& "$3$m{$2}$1" gt $d' xyz.log
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| perl, perl regex, regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|