sed/awk/grep help

Kaos

[H]ard|Gawd
Joined
Oct 14, 2003
Messages
1,328
I've got a particular log file line I'm trying to parse out and having some difficulty with.

Environment: Debian Linux, Bash Shell

I have a file that contains a record similar to this on each line

Code:
/home/user/run_folder/logs/20101014//export_01_start-101410-0230.log:Thu Oct 14 02:31:01 EDT 2010:Completed export_job for 20101014

I'm starting to work on a script that parses this data, I'll take the results using a loop likely and format it neatly into an html table for easy viewing.

The file contains lines built from another script that greps through every log file in that directory and finds the lines matching 'completed' - I can re-write/edit that script if need be.

I really only care about the date/time "Thu Oct 14 02:31:01 EDT 2010" and the message "Completed export_job for 20101014" and even the "for 20101014" isn't necessary.

I've been scratching my head over this for the better part of the afternoon.

I really couldn't find a character to use awk to split the line up in any way that made sense, I initially thought I could use the semicolon...but then it splits up the time.

Any tips or even basic thoughts on how to go about this would be appreciated since I'm new to sed/awk and regular expressions in general.
 
I really couldn't find a character to use awk to split the line up in any way that made sense, I initially thought I could use the colon...but then it splits up the time.

So? Just chop the string by the colons, toss what you don't need and put colons back in to reformat the date

Code:
cat input | awk 'BEGIN { FS=":"}; {print $2 ":" $3 ":" $4 ", " $5}'
returns
Code:
Thu Oct 14 02:31:01 EDT 2010, Completed export_job for 20101014
 
Last edited:
Thanks a ton for the response, honestly.

How would you suggest tossing what I don't need? Do some kind of pattern match to the long filename and replace it with nothing?

I'm pretty new to this but trying to get through a couple o'reilly books (sed and awk, bash cookbook) to get a better handle on it.

edit: sorry - just was able to test it (posted that from my phone).

Thanks!
 
Last edited:
Back
Top