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
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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用户在图形界面登录