I have a log file which roughly looks like this:
Sep 23 10:28:26 node kernel: em0: device is going DOWN
Sep 23 10:28:26 node kernel: em0: device is going UP
Sep 23 10:29:14 node cdsmon: /tmp/instance0 ; core dumped
Sep 23 10:29:14 node cdsmon: /tmp/instance0 ; core dumped
Sep 23 10:28:26 node kernel: em0: device is going DOWN
Sep 23 10:29:14 node cdsmon: /tmp/instance1 ; core dumped
Sep 23 10:28:26 node kernel: em0: device is going UP
Sep 23 10:29:14 node cdsmon: /tmp/instance2 ; core dumped
I want to detect the lines with cdsmon
and then split the line by ;
(to get the /tmp/instance0
and the event like core dumped
).
For this I used sed
as:
sed -u -n -e "s/^.*cdsmon: //p" /tmp/dev.log
which gives output as:
/tmp/instance0 ; core dumped
/tmp/instance0 ; core dumped
/tmp/instance1 ; core dumped
/tmp/instance2 ; core dumped
But upon piping this output to awk
as shown below, it gives the same output as above:
sed -u -n -e "s/^.*cdsmon: //p" /tmp/dev.log | awk -F ";" "{print $1}"
The same is observed despite removing the -u
option from sed
.
Can anyone please point out if I'm missing anything? I'm using a FreeBSD box with regular awk/sed and unfortunately cannot install any new package.
s/old/new/
with no variables in the search or replacement sections you can easily beat a sed oneliner for robustness, portability, efficiency, clarity, etc. so YMMV.