Reputation: 1220
I have an irc log as follows
04/14/13 21:38<@Hamatti> Lorem ipsum dolor sit amet
04/14/13 21:39<@Hamatti> consectetur adipiscing elit.
04/14/13 21:45<@Hamatti> Duis facilisis convallis lacus
EDIT1. sorry, I was not clear with my intentions. So I would want the output for the previous to be
21:38<@Hamatti> Lorem ipsum dolor sit amet
21:39<@Hamatti> consectetur adipiscing elit.
21:45<@Hamatti> Duis facilisis convallis lacus
so the time is important.
EDIT2 There is also part of the logs, the earlier ones in format
20:12<@Hamatti> Something.
20:13<@Hamatti> Funny.
20:13<@Hamatti> Happened.
and I need those lines to be non-modified.
and since my old logs are in format with no date stamp, I would like to remove the date from later logs.
sed 's/[0-9]{2}\/[0-9]{2}\/[0-9]{2}//g' logfile
Regex in the sed seems to work in regex testers but this sed is not doing anything. I wonder where is the problem? Any tips with bash tools (sed, awk, etc) are highly welcomed. Since only part of the logs have the date, I can't use something like
awk '{$1 = ""; print}'
because I would need the checking first.
Upvotes: 4
Views: 7477
Reputation: 5039
The cut command is easy to apply here:
cut -d " " -f "2-" logfile
It means:
If every line is split by an space (delimiter, -d option) then take all items from the second one onwards.
Upvotes: 3
Reputation: 785058
This sed command will do the job:
sed -i.bak 's/^[^<]*//' logfile
EDIT: Based on your comment, this will only clear date part and preserve the timestamp:
sed -i.bak 's/^[^ ]* //' logfile
EDIT 2: Based on your 2nd time edited question:
sed -i.bak 's#^[0-9]*/[0-9]*/[0-9]* ##' logfile
OR use extended regex capability in sed like this:
Mac:
sed -E -i.bak 's#^[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,2} ##' logfile
Linux:
sed -r -i.bak 's#^[0-9]{1,2}/[0-9]{1,2}/[0-9]{1,2} ##' logfile
Upvotes: 7