0

我有一个文件,内容如下,

    /hello/dir1/dir2/remove_til_here/code/dira/dir1/a.c
    /hello/dir1/dir2/remove_til_here/code/dirb/dir7/b.c
    /hello/dir1/dir2/remove_til_here/code/dirc/dir3/c.c
    /hello/dir1/dir2/remove_til_here/code/dird/dir2/d.c
    ......

我想要 o/p 如下:

code/dira/dir1/a.c
code/dirb/dir7/b.c
code/dirc/dir3/c.c
code/dird/dir2/d.c

我想避免/hello/dir1/dir2/remove_stil_here/所有线路中的字符串。请对此有所了解。我试过了,cat file | awk '{print $5}'但是没有用,提前谢谢!

4

2 回答 2

4

怎么样sed

sed 's|^.*remove_til_here/||'

对于非贪婪匹配,我认为您也可以使用 perl - 不,等等,不要逃跑:

perl -pe 's|^(.*?)remove_til_here/||' file
于 2013-09-06T10:28:03.410 回答
1

由于要删除的模式是固定路径,因此您知道存在多少目录分隔符。所以不妨使用cut

cut -d/ -f6- inputfile
于 2013-09-06T10:34:06.540 回答