linux 中删除文本中第一个.号之前的内容

 

001、方法1 利用cut

复制代码
[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# 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 test01]# cut -d "." -f 2- a.txt      ## cut
002.003.004.005
007.008.009.010
012.013.014.015
017.018.019.020
022.023.024.025
027.028.029.030
复制代码

 

002、方法2 ,利用sed

复制代码
[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# 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 test01]# sed 's/\S\+\.//' a.txt         ## 有点奇怪
005
010
015
020
025
030
[root@pc1 test01]# sed 's/\S[^.]\+\.//' a.txt     ## 需要多加一层否定
002.003.004.005
007.008.009.010
012.013.014.015
017.018.019.020
022.023.024.025
027.028.029.030
复制代码

 

003、方法3, 利用awk

a、

复制代码
[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# 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                                               ## awk实现
[root@pc1 test01]# awk -F "." '{for(i = 2; i < NF; i++) {printf("%s.", $i)} {print $NF}}' a.txt
002.003.004.005
007.008.009.010
012.013.014.015
017.018.019.020
022.023.024.025
027.028.029.030
复制代码

 

b、

复制代码
[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# 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 test01]# awk '{sub(/[0-9]+\.*/, ""); print $0}' a.txt     ## 借助awk,sub正则替换命令实现
002.003.004.005
007.008.009.010
012.013.014.015
017.018.019.020
022.023.024.025
027.028.029.030
复制代码

 

 

004、 借助循环 +  字符串处理

复制代码
[root@pc1 test01]# ls
a.txt
[root@pc1 test01]# 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 test01]# cat a.txt | while read i; do echo ${i#*.}; done  ## 借助循环 + 字符串处理实现
002.003.004.005
007.008.009.010
012.013.014.015
017.018.019.020
022.023.024.025
027.028.029.030
复制代码

 。

 

posted @   小鲨鱼2018  阅读(224)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-10-10 关闭anaconda3 默认自动启动的命令
2022-10-10 github.com[0: 192.30.255.113]: errno=Connection refused
2022-10-10 centos7 中安装java8
2022-10-10 configure: error: HTSlib development files not found
2022-10-10 configure: error: htscodecs submodule files not present.
2022-10-10 utils.c:33:18: fatal error: zlib.h: No such file or directory
2021-10-10 ubuntu中root用户在图形界面登录
点击右上角即可分享
微信分享提示