I have a huge file on my unix server from which I need to extract certain parts
The format of the line is
aNumber timestamp commandInformation
I use the command
grep LATENCY file.log | grep CMDTYPE=NEW
to filter out certain lines that I want. I only want the part timestamp and the last 9 characters from the line to be returned, not the complete line. How can I do that?
You can do it all with grep
using -o
which outputs only the match and not the whole line.
Assuming you can create a regex for the timestamp and the rest of the line, you could simply add:
... | grep -o regex
[Added answer for anyone else who lands here trying to extract part of a line using grep
where the regex is the part they want to extract.]
cut
must do the job
grep something somewhere | grep againsomething | cut -f2 -d' '
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With