linux 中 如何提取文件的最后几列、删除最后几列

 

001、提取文件的最后几列

[root@pc1 test3]# ls
a.txt
[root@pc1 test3]# cat a.txt                   ## 测试文件
001 002 003 004 005 006 007 008 009 010
011 012 013 014 015 016 017 018 019 020
021 022 023 024 025 026 027 028 029 030
[root@pc1 test3]# rev a.txt | cut -d " " -f 1-3 | rev   ## 提取文件的最后3列
008 009 010
018 019 020
028 029 030

 

 

002、删除文件最后几列

[root@pc1 test3]# ls
a.txt
[root@pc1 test3]# cat a.txt                ## 测试文件
001 002 003 004 005 006 007 008 009 010
011 012 013 014 015 016 017 018 019 020
021 022 023 024 025 026 027 028 029 030
[root@pc1 test3]# rev a.txt
010 900 800 700 600 500 400 300 200 100
020 910 810 710 610 510 410 310 210 110
030 920 820 720 620 520 420 320 220 120
[root@pc1 test3]# rev a.txt | cut -d " " -f 4- | rev     ## 删除文件的最后3列
001 002 003 004 005 006 007
011 012 013 014 015 016 017
021 022 023 024 025 026 027

 

posted @ 2022-11-02 12:02  小鲨鱼2018  阅读(388)  评论(0编辑  收藏  举报