linux 中取文本的最后一列

 

001、测试数据, awk实现

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt                      ## 测试数据
01 02 03 04 05
06 07 08 09 10
11 12    13 14  15
16 17 18 19             20
21 22 23 24 25
26 27    28 29         30
31 32 33 34 35
36 37 38 39 40
[root@pc1 test]# awk '{print $NF}' a.txt       ## awk实现
05
10
15
20
25
30
35
40

 

002、sed实现

[root@pc1 test]# ls
a.txt
[root@pc1 test]# cat a.txt                            ## 测试数据
01 02 03 04 05
06 07 08 09 10
11 12    13 14  15
16 17 18 19             20
21 22 23 24 25
26 27    28 29         30
31 32 33 34 35
36 37 38 39 40
[root@pc1 test]# sed 's/\(.*\s\)\(.*\)/\2/' a.txt     ## 借助sed预存储实现,\1贪婪匹配空格或者制表符,实现删除空格或者制表符之前的数据
05
10
15
20
25
30
35
40

 。

 

posted @ 2023-12-29 21:46  小鲨鱼2018  阅读(95)  评论(0编辑  收藏  举报