2014-09-22 53 views
0

開始我有一個固定寬度的文件是這樣的:如何刪除第二列的第一性格特徵,如果它與零

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  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 

回答

0

這應該使:

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 
相關問題