Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

309
Visualizações
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?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

This might work for you:

sed G file
over 4 years ago · Santiago Trujillo Relatório

0

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
over 4 years ago · Santiago Trujillo Relatório

0

You can try this sed,

sed '/SOME_TEXT/s/.*/&\n/g' logfile.log

Or

sed '/SOME_TEXT/G' logfile.log
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda