Replacing last characters after last comma with a string

前端 未结 4 967
庸人自扰
庸人自扰 2021-01-27 23:24

I have a huge text file which look like this:

36,53,90478,0.58699759849,0.33616,4.83449759849,0.0695335954050315,3
36,53,90478,0.58699759849,0.33616,4.8344975984         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 23:37

    This is the answer that @RomanPerekhrest provided at my cross-question (I was also seeking unix/perl solutions) here:

    awk approach with sprintf function(to add leading zeros):

     awk -F, -v OFS=',' '$8="MI-"sprintf("%02d",$8);' file
    

    The output:

    36,53,90478,0.58699759849,0.33616,4.83449759849,0.0695335954050315,MI-03
    36,53,90478,0.58699759849,0.33616,4.83449759849,0.0695335954050315,MI-08
    36,53,90478,0.58699759849,0.33616,4.83449759849,0.0695335954050315,MI-14
    36,53,15596,0.58454577855,0.26119,2.24878677855,0.116147072052964,MI-12
    

提交回复
热议问题