4

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?

chepner
  • 497,756
  • 71
  • 530
  • 681
Dawny33
  • 10,543
  • 21
  • 82
  • 134

3 Answers3

3

You can use this sed:

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

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

anubhava
  • 761,203
  • 64
  • 569
  • 643
2

try this;

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

Ex;

user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//'
"a","b","c"
Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24
1

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
P....
  • 17,421
  • 2
  • 32
  • 52