noviceuser has asked for the wisdom of the Perl Monks concerning the following question:

suppose i have multiple lines like below and i want to grep lines having "code" only after fixed pattern "/dir1/dir2/100.10/dir3/100.20/" . i have tried using grep "/code/",but it is giving all the lines containing the match elsewhere. please help

/dir1/dir2/100.10/dir3/100.20/code/abc/def.txt /dir1/dir2/100.10/dir3/100.20/code/def/ghi.txt . .

Replies are listed 'Best First'.
Re: regex in perl
by Corion (Patriarch) on Oct 21, 2021 at 09:56 UTC

    What prevents you from grepping for /dir1/dir2/100.10/dir3/100.20/code then?

Re: regex in perl
by perlfan (Parson) on Oct 22, 2021 at 18:17 UTC
    It's doing exactly what you're telling it to do since code (heh) is in the examples you. grep works conceptionally the same way as the utility, so you need to define a regexp that's sufficiently selective.