I am analyzing log files from my server(particular few lines from there). But those lines are having around 1000 to 2000 characters in length.
Here is an example how the lines are coming out with grep
and less
with following command.
tail -n 1000 log.log | grep 'SOME_TEXT' | less
Output:
random text SOME_TEXT another 1000 chars
random SOME_TEXT 2000 chars
text text SOME_TEXT 2000 chars
But its hard for me to separate them as those are screen full of texts(also not pleasant for eyes either). I want to have my output like blow:
random text SOME_TEXT another 1000 chars
random SOME_TEXT 2000 chars
text text SOME_TEXT 2000 chars
And I have modified my above command with sed
:
tail -n 1000 log.log | grep 'SOME_TEXT' | sed 's/\n/\n\n/' | less
It didn't work, so I tried with tr
next:
tail -n 1000 log.log | grep 'SOME_TEXT' | tr '\n' '\n\n' | less
It didn't work with me either. What am I missing here?
This might work for you:
sed G file
This will search for pattern
and print only pattern
with an extra blank line after it.
awk '/SOME_TEXT/ {print $0 RS}' file
Example:
cat file
test
more
SOME_TEXT my data
more
even more
SOME_TEXT need more
more data
yes
awk '/SOME_TEXT/ {print $0 RS}' file
SOME_TEXT my data
SOME_TEXT need more
To print all text, with a blank line after pattern
awk '8; /SOME_TEXT/ {print ""}' file
test
more
SOME_TEXT my data
more
even more
SOME_TEXT need more
more data
yes
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