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

180
Vistas
Replace wrong lines in csv

I have a csv file like that :

0;test1;description;toto
1;test2;description;tata
2;test3;desc
ription;tutu
3;test4;description;tete

In shell, I would like to replace all the line that doesn't start with a number. In this exemple I want to replace \nription by ription

I don't find the correct expression with sed, grep... :(

I want this result :

0;test1;description;toto
1;test2;description;tata
2;test3;description;tutu
3;test4;description;tete

Thanks a lot

EDIT 1 : I have try something like this :

LC_ALL=C tr '(\n)[0-9]' ' ' < hotels.csv > test.csv

Or this :

sed ':a;N;$!ba;s/\r\n?![0-ç-9]/ /g' hotels.csv 

But i think my regex is wrong and it doesn't work :(

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

With awk this seems feasible:

awk -F ';' '{if (NR>1  && match($1,/^[0-9]+$/)) printf("\n"); printf("%s",$0);} END{printf("\n")}' infile.csv

What it does:

  • from the second line: check if first field is a number and print a newline
  • in any line: print the entire line ($0) without trailing newline

Output is sent to STDOUT, input comes from infile.csv

EDIT: Sorry, i missed to copy the match(...)

over 4 years ago · Santiago Trujillo Denunciar

0

Using grep -P

grep -P "^\d" file.csv 

Use grep to match lines that begin with a digit.

over 4 years ago · Santiago Trujillo Denunciar

0

due to peculiarities of sed's pattern space processing, you will have to use something like this ..

Note: ~ must be a char not present in your text

$cat file
0;test1;description;toto
1;test2;description;tata
2;test3;desc
ription;tutu
3;test4;description;tete
$ sed 'N;s/\n/~/' file | sed -r 's/~([0-9])/\n\1/g;s/~//g'
0;test1;description;toto
1;test2;description;tata
2;test3;description;tutu
3;test4;description;tete

PS: if your input file has Windows line endings you will have to use \r\n instead of \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