linuxsedgreptrless-unix

Adding additional newline between each line


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?


Solution

  • This might work for you:

    sed G file