我有一个文件,内容如下,
/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 文件 | awk '{print $5}'
但是没用,
提前致谢!
最佳答案
sed
怎么样?
sed 's|^.*remove_til_here/||'
对于非贪婪匹配,我认为你也可以使用 perl - 不,等等,不要逃跑:
perl -pe 's|^(.*?)remove_til_here/||' file
关于linux - 如何避免文件中所有行开头的特定字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18655585/