[英]How can I avoid particular string from beginning of all the lines in a file?
I have a file, the contents are like below, 我有一个文件,内容如下
/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
......
I want o/p as below: 我要如下所示的o / p:
code/dira/dir1/a.c
code/dirb/dir7/b.c
code/dirc/dir3/c.c
code/dird/dir2/d.c
I want to avoid string /hello/dir1/dir2/remove_stil_here/
from all the line. 我想避免所有/hello/dir1/dir2/remove_stil_here/
字符串/hello/dir1/dir2/remove_stil_here/
。 Please shed some light on this. 请对此有所说明。 I have tried with cat file | awk '{print $5}'
我已经尝试过cat file | awk '{print $5}'
cat file | awk '{print $5}'
But it's of no use, thanks in advance! cat file | awk '{print $5}'
但这没有用,谢谢!
How about sed
? sed
怎么样?
sed 's|^.*remove_til_here/||'
For a non-greedy match I think you can also use perl - no, wait, don't run away: 对于非贪婪的比赛,我认为您也可以使用perl-不,请稍等,不要逃避:
perl -pe 's|^(.*?)remove_til_here/||' file
Since the pattern to be removed is a fixed path , you know how many directory separators are present. 由于要删除的模式是固定路径 ,因此您知道存在多少个目录分隔符。 So might as well use cut
: 所以不妨使用cut
:
cut -d/ -f6- inputfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.