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/
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/