remove first few characters from each line

Hi,

I have a file with lines like below.
I need to remove first few characters from each line until a date format is found.

05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR:
05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR:
51129.77605/02/12 11:44:32 NEARRIDGIDAGHLAR@98.251.109.147{E889D36D2B2082668147CB1E0A47A91B.tomcat1}TP-Processor26 LogExchUsage:
18797.45204/13/12 06:55:40 BYE67BYE@96.254.176.116{3FC897AF82897CF3683FE06D6A21997E.tomcat8}TP-Processor18 LogExchUsage: ERROR:
Request for getNextPage.................04/26/12 06:44:20 BAOBEIBUNNY@96.242.252.247{2E29DD4B985715A69EA18021E6EB088B.tomcat4}TP-Processor29 LogExchUsage:

I need to remove first few characters from each line until a date format is found.
out put should be like this.

05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR: 
05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR:
05/02/12 11:44:32 NEARRIDGIDAGHLAR@98.251.109.147{E889D36D2B2082668147CB1E0A47A91B.tomcat1}TP-Processor26 LogExchUsage:
04/13/12 06:55:40 BYE67BYE@96.254.176.116{3FC897AF82897CF3683FE06D6A21997E.tomcat8}TP-Processor18 LogExchUsage: ERROR:
04/26/12 06:44:20 BAOBEIBUNNY@96.242.252.247{2E29DD4B985715A69EA18021E6EB088B.tomcat4}TP-Processor29 LogExchUsage: 

Any clue...

$ nawk -F\/ -v OFS=\/ '{if(length($1)>2){$1=substr($1,length($1)-1,2)}}1' input.txt
05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR:
05/06/12 20:47:02 GUMGUY@98.192.174.74{42B42A72AC955F5926621273E3A15059.tomcat2}TP-Processor15 LogExchUsage: ERROR:
05/02/12 11:44:32 NEARRIDGIDAGHLAR@98.251.109.147{E889D36D2B2082668147CB1E0A47A91B.tomcat1}TP-Processor26 LogExchUsage:
04/13/12 06:55:40 BYE67BYE@96.254.176.116{3FC897AF82897CF3683FE06D6A21997E.tomcat8}TP-Processor18 LogExchUsage: ERROR:
04/26/12 06:44:20 BAOBEIBUNNY@96.242.252.247{2E29DD4B985715A69EA18021E6EB088B.tomcat4}TP-Processor29 LogExchUsage:

Thanks. It worked, But if a slash '/' (delim) comes in front of the date stamp then the output will be errored?

99918/797.45204/13/12 06:55:40 BYE67BYE@96.254.176.116{3FC897AF82897CF3683FE06D6A21997E.tomcat8}TP-Processor18 LogExchUsage: ERROR:

will be

18/797.45204/13/12 06:55:40 BYE67BYE@96.254.176.116{3FC897AF82897CF3683FE06D6A21997E.tomcat8}TP-Processor18 LogExchUsage: ERROR:

ok. make it simpler

 
nawk -F: -v OFS=":" '{$1=substr($1,length($1)-10,11)}1' input.txt
1 Like

Thanks Raj.. But even in the above code there is a chance of error. Because we can expect any characters as unwanted stream of texts in front. I need to start the line with datestamp
Want to know how to find some date time format.
something like

[0-9][0-9]/[0-9][0-9/[0-9][0-9] [0-9][0-9]:[0-9][0-9:[0-9][0-9] 

check this.

But the below will match the incorrect date also ( eg. 88/99/99 xx:xx:xx )

check the regex pattern and correct it

 
nawk '{if(match($0,"[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]")){print substr($0,RSTART,length($0))}}' input.txt
1 Like

Hi Itkamaraj,

Just want to know why we keep

  ......}1' input.txt [\code] at the end of code.
 
 

nawk -F: -v OFS=":" '{$1=substr($1,length($1)-10,11)}1' input.txt

Also do we not have any way to read string from backside by speicifying index as -.

Thanks
Krsnadasa

---------- Post updated at 07:47 AM ---------- Previous update was at 07:46 AM ----------

Sorry I mean what is the significance of 1.

Everything in awk has the form condition{action} . If the condition evaluates to 1 then the action is performed. If the condition is omitted then the default condition is 1, so the action is always performed. If the action is omitted then the default action is performed, which is {print $0} . In this case the condition is "1" so that evaluates to 1 and the action is omitted, therefore {print $0 } is performed, which is "print the entire record".

Many thanks Scruit,