Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: matching multiple words within multiple lines in a file

by kaushik9918 (Sexton)
on Dec 02, 2014 at 09:20 UTC ( [id://1108931]=note: print w/replies, xml ) Need Help??


in reply to Re: matching multiple words within multiple lines in a file
in thread matching multiple words within multiple lines in a file

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: matching multiple words within multiple lines in a file

Replies are listed 'Best First'.
Re^3: matching multiple words within multiple lines in a file
by Corion (Patriarch) on Dec 02, 2014 at 09:27 UTC

    Where exactly do you have problems with the linked nodes?

    It helps us help you better if you provide the code you've already written, together with input data, and also the output it generates and the output you expect.

      Thanks for your reply. firstly, I am a beginner. I am trying to write a code to do the following. suppose this is my input text file in the format
      abc dsdasd dasgg gfg htrh sdsjk sdasd ds { abc deef gheweri rew jk \ dfs grg gre ret rtr lm nop qrs\ erwe erewr gf htrh ksdj \} -fdj lf erew fsdfj kgfk -bg1 abc dfsdf -bg2 nop fdsfs
      Now - I wanted to write a PERL code to know if the string 'abc', 'dfsdf' , 'nop' and 'fdsfs' in line #5 exist between '{' and '}'. I am not able to figure out how to write the code to implement this. In case of the text file provided above, the result should be something printed like
      'abc' and 'nop' are present above

        In my opinion, the link to Parsing a file with parentheses to build a hash is relatively suitable, as it points to a very similar problem, extracting terms between ( and ) instead of { and }.

        Depending on the nature of your data, you might be able to simply extract all pairs of {...} and then check those for your keywords. A very simplicistic parser would be:

        my $line= 'abc ... {abc} ... abc'; my @terms= $line =~ /\{(.*?)\}/g; for my $bracketed (@terms) { print "$bracketed matches $1" if ($bracketed =~ /(abc|nop)/); };

        This does not care for nested sets of brackets. For parsing nested sets, see the linked node.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found