Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: grep return the entire file not the line which matches

by FunkyMonk (Chancellor)
on Aug 03, 2011 at 15:41 UTC ( [id://918311]=note: print w/replies, xml ) Need Help??


in reply to grep return the entire file not the line which matches

After fixing your lack of strictures, as suggested by moritz and Corion, you still have a problem. The first argument of grep is not a string to search for, rather, it should be an expression (/$en/, for example).

You'll end up with something like:

open(ENG,"<en_1000") or die $!; my @eng_dat=<ENG>; close ENG; my $en="EN-1000-0003-3"; my @data= grep /$en/,@eng_dat; print @data;

Replies are listed 'Best First'.
Re^2: grep return the entire file not the line which matches
by vikashiiitdm (Novice) on Aug 03, 2011 at 17:07 UTC

    dear monk, thanks for the correction. my en_1000 file is made up of such lines and i need to extract the whole line based upon the id provided.

     <p id=EN--1000-0003-3> The object turned out to be a big meteorite. Uttama was delighted. He had never seen anything like it on sea or land before. Despite its journey in space and stay in water, it had retained its shape and colour.  </p>

      You still got the same problem there about which I told you a week ago. "EN--1000-0003-3" is not the same as "EN-1000-0003-3". Don't you see that in file there are two "-" after the EN, whereas in the search string there is only one "-".

      To make it even more obvious:

      EN--1000-0003-3 is not the same as EN-1000-0003-3
      The example I gave will match the all of the lines that contain the search phrase. Perhaps you should try my example with your data and see what happens.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-16 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found