Tuesday, June 30, 2009

Perl Regex - Example 1

Case: I have a file which reads like below. I need to remove the date stamp & also the "[filername: ses.exceptionShelfLog:info]:" text.


$ cat filername_exception_error | tail
Thu Jun 4 09:43:40 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0d ESH module A shelf id 1.
Thu Jun 4 09:43:47 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0d ESH module A shelf id 1.
Thu Jun 4 09:43:49 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0c ESH module A shelf id 1.
Thu Jun 4 09:50:20 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0d ESH module B shelf id 4.
Thu Jun 4 09:50:40 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0d ESH module A shelf id 5.
Thu Jun 4 09:50:51 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0d ESH module B shelf id 5.
Thu Jun 4 09:51:01 PDT [filername: ses.exceptionShelfLog:info]: Shelf Log information on channel 0d ESH module B shelf id 6.

The regular expression to do this is:
$ cat filername_exception_error  | perl  -pe "s/\d\d:\d\d:\d\d//g" |  perl -i  -pe "s/\[filername: ses.exceptionShelfLog:info]://g" | tail 
Thu Jun 25 PDT Shelf Log information on channel 4d ESH module A shelf id 2.
Thu Jun 25 PDT Shelf Log information on channel 4d ESH module A shelf id 3.
Thu Jun 25 PDT Shelf Log information on channel 4d ESH module B shelf id 1.
Thu Jun 25 PDT Shelf Log information on channel 4d ESH module B shelf id 2.
Thu Jun 25 PDT Shelf Log information on channel 4d ESH module B shelf id 3.
Fri Jun 26 PDT Shelf Log information on channel 4d ESH module B shelf id 2.
Sat Jun 27 PDT Shelf Log information on channel 4d ESH module B shelf id 2.
Sun Jun 28 PDT Shelf Log information on channel 4d ESH module B shelf id 2.
Mon Jun 29 PDT Shelf Log information on channel 4d ESH module B shelf id 2.
Tue Jun 30 PDT Shelf Log information on channel 4d ESH module B shelf id 2.

No comments:

About Me

My photo
Unix geek with AWS, Cloud computing, Linux, Netapp, VMware, Scripting background! :)