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
  • 446,329
  • 63
  • 468
  • 610
Dawny33
  • 9,571
  • 15
  • 75
  • 124

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
  • 713,503
  • 59
  • 514
  • 593
1

try this;

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

Ex;

user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//'
"a","b","c"
Mustafa DOGRU
  • 3,814
  • 1
  • 12
  • 20
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....
  • 14,772
  • 2
  • 24
  • 42