Skip to content
Advertisement

Removing leading 0 from third column

I’m trying to remove the first 0 from the third column in my CSV file

tel.csv –

 test,01test,01234567890
 test,01test,09876054321

I have been trying to use the following with no luck –

cat tel.csv | sed 's/^0*//'

Advertisement

Answer

Something like:

sed 's/^([^,]*),([^,]*),0(.*)$/1,2,3/' file.csv

Or awk

awk 'BEGIN{FS=OFS=","}{sub(/^0/, "", $3)}1' file.csv
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement