strip leading zeros in awk program

后端 未结 5 1500
孤城傲影
孤城傲影 2020-12-19 20:28

So I\'m pretty lost as I missed a week and am playing catch up, but I\'m to write an awk program to tell the difference, in days, between two dates.

I\'m more or les

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 21:29

    I tried the answer suggested by @paxdiablo. It ended up stripping the non-leading zeros as well.

    $ echo '20/02/1965' | awk '{gsub ("^0*", "", $0); gsub ("/0*", "/", $0); print}'
    2/2/1965
    

    Using sub instead gsub worked fine for me.

    $ echo '20/02/1965' | awk '{sub ("^0*", "", $0); sub ("/0*", "/", $0); print}' 
    20/2/1965
    

提交回复
热议问题