linux中正则表达式仅保留绝对路径的目录

发布时间 2023-09-19 20:27:58作者: 小鲨鱼2018

 

001、 方法1

[root@pc1 test2]# ls
a.txt
[root@pc1 test2]# cat a.txt      ## 测试文件
/home/test2/a.txt
[root@pc1 test2]# sed -r 's/(\/.*\/).*/\1/' a.txt     ## 仅保留路径
/home/test2/