Reputation: 39
I have this Command :
cat -n file.log | grep "Start new test" | tail -1 | cut -f 1 | xargs -I % sed -n %',$s/is not alive/&/p' file.log
That gives the output of the whole line :
Jan 19 23:20:33 s_localhost@file platMgt.xbin[3260]: blade 10 is not alive
Jan 19 23:20:33 s_localhost@file platMgt.xbin[3260]: blade 11 is not alive
how can I modify it to get the last part only : blade 11 is not alive
can I modify that in a way to display :
Error:blade 11 is not alive ?
Thank you for your response
Upvotes: 0
Views: 84
Reputation: 784888
To get the last part after colon awk is better tool:
s='Jan 19 23:20:33 s_localhost@file platMgt.xbin[3260]: blade 10 is not alive'
awk -F':' '{print "Error:" $NF}' <<< "$s"
blade 10 is not alive
EDIT: WIth your piped commands you can combine it as:
grep "Start new test" file.log|tail -1|awk -F':' '{print "Error:" $NF}'
PS: Though this whole thing is possible in awk itself.
Upvotes: 1
Reputation: 2182
You can use cut to delimit it on the colons and then add the error message:
cat -n file.log | grep "Start new test" | tail -1 | cut -f 1 | xargs -I % sed -n %',$s/is not alive/&/p' file.log | cut -d: -f 4 | xargs -I % echo Error: %
Upvotes: 2
Reputation: 184
The following obtains the the last ":" separated field with a sed command,
cat text.txt | sed 's/^.*: \([^:]*$\)/\1/g'
Upvotes: 0