Removing leading 0 from third column

Issue

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*//'

Solution

Something like:

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

Or awk

awk 'BEGIN{FS=OFS=","}{sub(/^0/, "", $3)}1' file.csv

Answered By – Jetchisel

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published