I have a csv file in which some lines begin with a comma, so I want to delete all of them.
Example: In this line:, ,"a","b","c"I want to remove the first comma.
,"a","b","c"
How to do this in bash?
You can use this sed:
sed
sed -i '' 's/^[[:blank:]]*,//' file.csv
^[[:blank:]]*, will match a comma at the beginning of the line with optional spaces before the comma.
^[[:blank:]]*,
try it;
sed 's/^,//' csvFile > newCSVfile
Example
user@host:/tmp$ echo ',"a","b","c"' | sed 's/^,//' "a","b","c"
Do not use the "g" flag in sed, it will help you remove only the first match ","
echo ',"a","b","c"' | sed 's/^,//'
For file:
sed -i.bak 's/^,//' infile.log
Source: https://habr.com/ru/post/1651493/More articles:Ошибка при запуске приложений загрузки Spring - Ошибка при создании bean с именем 'entityManagerFactory', определенным в ресурсе пути класса - springOCR to extract text from cedula / pass C # - c #The memory size of large algebraic data types - haskellEcto.DateTime and time zones - datetimePandas plot, merge two plots - pythonWhy sonar requires binaries (sonar.binaries) - sonarqubeThe name of the navigation element disappeared when pressed - androidmedia player prepareAsync () illegal state Android exception - androidПопытка вызова R script из приложения С# - c#Angular 2 rxjs time callback - angularAll Articles