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?
You can use this sed
:
sed -i '' 's/^[[:blank:]]*,//' file.csv
^[[:blank:]]*,
will match comma at line start with optional whitespaces before comma.
try this;
sed 's/^,//' csvFile > newCSVfile
Ex;
user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//'
"a","b","c"
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.