Reputation: 11081
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
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
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
Reputation: 4112
try this;
sed 's/^,//' csvFile > newCSVfile
Ex;
user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//'
"a","b","c"
Upvotes: 2