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 に答える