Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

Other than awk solution :

tr '\n' ' ' < Input.txt |sed 's/ //g' | tr '*' '\n'
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda