【问题标题】:how to delete first charecter of second column if it starts with zero如果第二列的第一个字符以零开头,如何删除它
【发布时间】:2014-09-22 22:05:49
【问题描述】:

我有一个这样的固定宽度文件:

FY14Working          BCT86   DI                Mattel Brands                      69.9900
FY14Working          BCT86   DC                Mattel Brands                      87.4900
FY14Working          0CT90   DC                Mattel Brands                      31.2400
FY14Working          BCK16   DC                Mattel Brands                      27.4900
FY14Working          0CT89   DC                Mattel Brands                      31.2400
FY14Working          BCK14   DC                Mattel Brands                      58.7400
FY14Working          01234   DC                Mattel Brands                      66.2400

如果它在第二列的第一个位置,我想从第二列中删除零。

输出应该是这样的:

FY14Working          BCT86   DI                Mattel Brands                      69.9900
FY14Working          BCT86   DC                Mattel Brands                      87.4900
FY14Working          CT90   DC                Mattel Brands                      31.2400
FY14Working          BCK16   DC                Mattel Brands                      27.4900
FY14Working          CT89   DC                Mattel Brands                      31.2400
FY14Working          BCK14   DC                Mattel Brands                      58.7400
FY14Working          1234   DC                Mattel Brands                      66.2400

【问题讨论】:

    标签: unix


    【解决方案1】:

    这应该是:

    awk '{gsub(/^0/,"",$2)}1' file
    

    要保持格式,请添加| column -t

    $ awk '{gsub(/^0/,"",$2)}1' file | column -t
    FY14Working  BCT86  DI  Mattel  Brands  69.9900
    FY14Working  BCT86  DC  Mattel  Brands  87.4900
    FY14Working  CT90   DC  Mattel  Brands  31.2400
    FY14Working  BCK16  DC  Mattel  Brands  27.4900
    FY14Working  CT89   DC  Mattel  Brands  31.2400
    FY14Working  BCK14  DC  Mattel  Brands  58.7400
    FY14Working  1234   DC  Mattel  Brands  66.2400
    

    【讨论】:

      猜你喜欢
      • 2022-08-17
      • 1970-01-01
      • 2022-11-24
      • 2023-03-19
      • 2013-05-21
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      相关资源
      最近更新 更多