Dren Dren - 3 months ago 7
Bash Question

parsing strings using either grep,awk or sed

I have a file with lines like below

17:59:49.987 - JobID 864563: Found 7 clips from SeqID 862753
17:59:49.987 - Processing Job 864562
17:59:50.003 - JobID 864561: Location 14695 applied clip data successfully. Updating OCAMT_GM_Sent
17:59:50.003 - Processing Job 864563
17:59:50.003 - JobID 864564
17:59:50.018 - JobID 864565
17:59:50.034 - Processing Job 864565
17:59:50.034 - JobID 864566
17:59:50.034 - JobID 864562
17:59:50.034 - JobID 864563
17:59:50.034 - Processing Job 864566
17:59:50.049 - JobID 864567
17:59:50.049 - JobID 864564
17:59:50.049 - Trying to send JobID 864566 to location 14623 at http://172.28.48.11/yb/ClipData.php. Retry count 0
17:59:50.049 - Processing Job 864567


I would like to capture certain strings so that its output file is something like below;

864563 17:59:49.987
864562 17:59:49.987
864561 17:59:50.003
864563 17:59:50.003


Since the the job id length is variable I am thinking of using regular expression \d+ and breaking the line in half using the word Job as a field separator but I am unsure if the following can be combined;

awk -F'Job*' '{print $1}'|awk '{print $1}'
awk -F'Job*' '{print $2}'

Answer

sed version:

sed -e 's/\([^ ]*\).*\(JobID \|Job \)\([0-9]\+\).*/\3 \1/g'

or with extended regex as pointed out by @spasic:

sed -E 's/^(\S+).*Job(|ID) ([0-9]+).*/\3 \1/'
Comments