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
  • 389,128
  • 51
  • 403
  • 529
Dawny33
  • 8,545
  • 11
  • 65
  • 121

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
  • 664,788
  • 59
  • 469
  • 547
1

try this;

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

Ex;

user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//'
"a","b","c"
Mustafa DOGRU
  • 3,704
  • 1
  • 11
  • 19
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....
  • 10,757
  • 1
  • 19
  • 38