Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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

by FunkyMonk (Chancellor)
on Aug 03, 2011 at 15:41 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2021-10-19 23:39 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (78 votes). Check out past polls.