On Thu, 2004-05-27 at 10:10, Jon Herbry wrote:
> Hi, anybody have idea find the number in a file? Assume I create a file call "sample"
> and have content below:
> ------------------------------------
> Hi, Jame where are you?
> How old are you?
> when you free?
> can you coming my home?
> -----------------------------------------
> assume if i want know string word "old" locate in which line and return the entire 
> sentences, so how i tell perl to find the string for example above? Please help.

If you're using a Unix system, try the command "grep". I do believe
MS-DOS like systems include a "find" utility with the same purpose.

If you're going with Perl, a script like this one will help:

======

#!/usr/bin/perl -nw
use strict;

my $word;

BEGIN { $word = shift || die "you must suply a word"; }

print if /\b$word\b/;

======

Something like that...

Basically, you take a word and, for each line of input, print it if it
matches the given word (surrounded by boundaries, so Frederick won't
match with Fred :-) )

HTH,

jac

> 
>               
> ---------------------------------
> Do you Yahoo!?
> Friends.  Fun. Try the all-new Yahoo! Messenger
-- 
Josà Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de InformaÃÃo


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to