UNIX用于删除多个文件中2个特定字段的最后一个字符的命令

时间:2017-05-27 17:01:00

标签: unix command

我是否知道如何编写Unix命令来删除所有行和多个文件中2个特定字段(第28和30列)的最后一个字符。

删除前的文件1示例:

0,0,1,14289067,10114404,145,60104212839,1,1,1,8801971507671,1,60104212839,1,8801971507671F,4,170523,170523,1,1,235045,235045,0,0,255,1,0,BMRBGBO,0,BWGKPEI,16758,2,6,00000000000,8801971507671,0,0,,FFFFFFFFFFFFFFFFFFFFFFFF,3
1,14286085,10114405,142,601124225298,1,1,1,1062895388906858,1,601124225298,1,1062895388906858F,41,170523,170523,1,1,235045,235045,0,1,255,1,0,BINDMAO,0,BWGKPAI,39285,2,6,00000000000,62895388906858,0,,FFFFFFFFFFFFFFFFFFFFFFFF,2

删除文件1中字段28和30中的最后一个字符后:

0,0,1,14289067,10114404,145,60104212839,1,1,1,8801971507671,1,60104212839,1,8801971507671F,4,170523,170523,1,1,235045,235045,0,0,255,1,0,BMRBGB,0,BWGKPE,16758,2,6,00000000000,8801971507671,0,0,,FFFFFFFFFFFFFFFFFFFFFFFF,3
1,14286085,10114405,142,601124225298,1,1,1,1062895388906858,1,601124225298,1,1062895388906858F,41,170523,170523,1,1,235045,235045,0,1,255,1,0,BINDMA,0,BWGKPA,39285,2,6,00000000000,62895388906858,0,,FFFFFFFFFFFFFFFFFFFFFFFF,2

然后我想继续下一个文件File 2并重复上面的相同过程。然后这应该继续,直到目录中的所有文件都完成。

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

您可以将指定分隔符的字段剪切为逗号。并且你使用sed命令来删除使用替换所需的字符。

cat filename | cut -d',' -f28 |sed s/(.*)./$1/g;