kunaal
kunaal

Reputation: 23

removing the null from csv file using shell

How to remove the null from csv file. 2015|||89019||2731||14.5|6.5|11.0|10.8|17.6|18.6|20.9|41.4|43.6||6.0|8.9|33.9|26.6|3.6|14.4|||6.6||55.1|20.3|8.0|12.5|1.1|0.3|2.7||56.6|37.4|6.0|9.7||33.3|43.4|3.9|1.8|17.6||32.8|37.0|20.6|0.8|0.0|7.5|1.4||52.1|47.9|1.09||89019|||405|0|0|3|600|436|1444||28.0|0.0|0.0|0.2|41.6|30.2|100.0||1134|310|21.5|46.3|53.7|2.41||20.7|8.5|9.9|17.1|19.3|8.1|9.5|3.4|3.5|59956|46368

As you can see there some null (empty) fields example:2nd and 3rd fields.

How can I remove them.

Upvotes: 0

Views: 41

Answers (2)

NeronLeVelu
NeronLeVelu

Reputation: 10039

sed 's/|\{2,\}/|/g' YourFile

Replace (s///) any (g) occurrence of at least 2 (\{2,\}\) character | by a single one

Upvotes: 0

bian
bian

Reputation: 1456

awk 'gsub("\\|+","|")' filename

sed 's:||*:|:g' filename

Upvotes: 1

Related Questions