Delete blank lines in csv file

I have a file with 4 million lines, each line ends with char $, but I mistakenly add a new line after the line separator when cleaning the website, so now it looks like this:

fist name, last name, phone, address, postal code, city, region,$

$

fist name, last name, phone, address, postal code, city, region,$

$

the new line "$" appears, of course, only if I use: set list, but I try to use this file for bulk insert in mysql, and now I am having problems with it.

I want to change the file:

fist name, last name, phone, address, postal code, city, region,$

fist name, last name, phone, address, postal code, city, region,$

How can i do this? with sed or awk or even vi? looked around, and what I found is really not relevant to this case.

please do not take into account the extra empty line shown above.

Thanks in advance

+4
source share
3

sed:

sed -i '/^$/d' yourfile.csv

, $:

sed -i '/^$$/d' yourfile.csv

sed -i; , . sed '/^$$/d' yourfile.csv > newfile.csv.

. :

sed '/^ *$/d' yourfile.csv

, . sed :

sed '/^[ X]*$/d' yourfile.csv

X , Control-V Tab.

sed [ \t\r]* \s* [[:space:]]*, -E.

+5

grep ( ) . :

grep -v '^$' yourfile.csv > yourfile_fixed.csv
0

:

awk:

awk 'NF' file > tmp && mv tmp file

sed ( , -i.bak):

sed -i '/^$/d' file

vi:

:g/^$/d
0

Source: https://habr.com/ru/post/1531459/


All Articles