Dawny33
Dawny33

Reputation: 11081

Remove first comma from a csv file in bash

I have a csv file in which some lines start with a comma, so I want to remove all of them.

Example: In this line: ,"a","b","c", I want to remove the first comma.

How do I do this in bash?

Upvotes: 4

Views: 1134

Answers (3)

anubhava
anubhava

Reputation: 784998

You can use this sed:

sed -i '' 's/^[[:blank:]]*,//' file.csv

^[[:blank:]]*, will match comma at line start with optional whitespaces before comma.

Upvotes: 4

P....
P....

Reputation: 18351

Do not use "g" flag in sed, it will help you in removing only first matching ","

echo ',"a","b","c"' | sed 's/^,//'

For file :

sed -i.bak 's/^,//' infile.log

Upvotes: 1

Mustafa DOGRU
Mustafa DOGRU

Reputation: 4112

try this;

sed 's/^,//' csvFile > newCSVfile

Ex;

user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//'
"a","b","c"

Upvotes: 2

Related Questions