Skip to content
Advertisement

How To replace leading zero with spaces in linux?

i have text like this

Jan 28|Jan 29|Jan 30|Jan 31|Feb 01|Feb 02|Feb 03|Feb 04

i want to the result like this

Jan 28|Jan 29|Jan 30|Jan 31|Feb  1|Feb  2|Feb  3|Feb  4

i have been searching all over and get no result, please help

Advertisement

Answer

With gawk you can use gensub:

awk '{print gensub(/ 0([0-9])/,"  \1", "g")}' file
Jan 28|Jan 29|Jan 30|Jan 31|Feb  1|Feb  2|Feb  3|Feb  4

Or same pattern with sed:

sed  's/ 0([0-9])/  1/g' file
Jan 28|Jan 29|Jan 30|Jan 31|Feb  1|Feb  2|Feb  3|Feb  4
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement