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 :(
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:
$0) without trailing newlineOutput is sent to STDOUT, input comes from infile.csv
EDIT: Sorry, i missed to copy the match(...)
Using grep -P
grep -P "^\d" file.csv
Use grep to match lines that begin with a digit.
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