Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by FunkyMonk (Canon)
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;


Comment on Re: grep return the entire file not the line which matches
Select or Download Code
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>
      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.

      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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2014-08-01 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (0 votes), past polls