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

245
Visualizações
Linux Script: substituting a multiple lines with single line of text

What shell script should I use in Linux to replace a group with n lines of text with a single line?

I have a file like :

a
b
c
*
d
e
f
*
g
h
i
*

and I want to get a file as:

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

0

can use awk

awk '{if ($0=="*"){print s;s=""}else{s=s$0}}' file

an bash way to this is

while read x
do
   [ "$x" == "*" ] && echo  || echo -n $x
done < file
over 4 years ago · Santiago Trujillo Relatório

0

sed way:

sed ':a;N;$!ba;s/\n//g' < t | sed 's:*:\n:g'

t is the file you want to change.

references: How can I replace a newline (\n) using sed? Why does sed not replace all occurrences?

The first command replaces \n with nothing. the second replaces * with \n.

sed is a very powerful stream editor tool by the way, knowing it can help you in more ways than you can imagine.

over 4 years ago · Santiago Trujillo Relatório

0

Other than awk solution :

tr '\n' ' ' < Input.txt |sed 's/ //g' | tr '*' '\n'
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