Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

regex in perl

by noviceuser (Novice)
on Oct 21, 2021 at 09:41 UTC ( #11137842=perlquestion: print w/replies, xml ) Need Help??

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 (Vicar) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11137842]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2022-05-27 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (94 votes). Check out past polls.

    Notices?