How to write filesearch with begin-pattern till end-pattern 
Author Message
 How to write filesearch with begin-pattern till end-pattern

In perl I can search through files,
matching every line between two patterns.
Example:

        perl -ne 'print "$ARGV:$_" if /black/ .. /cat/' *.txt

will print the lines (with the filename) between
'black' and 'cat' (including), from all txt files.

How can I do this in Ruby?

        -- Nico --



Tue, 02 Aug 2005 18:15:05 GMT  
 How to write filesearch with begin-pattern till end-pattern
Hi,

At Fri, 14 Feb 2003 19:15:05 +0900,

Quote:

> In perl I can search through files,
> matching every line between two patterns.
> Example:

>    perl -ne 'print "$ARGV:$_" if /black/ .. /cat/' *.txt

        ruby -ne 'print "#{ARGV}:#{$_}" if /black/ .. /cat/' *.txt

--
Nobu Nakada



Tue, 02 Aug 2005 18:28:32 GMT  
 How to write filesearch with begin-pattern till end-pattern

Quote:
> At Fri, 14 Feb 2003 19:15:05 +0900,

> > In perl I can search through files,
> > matching every line between two patterns.
> > Example:

> >       perl -ne 'print "$ARGV:$_" if /black/ .. /cat/' *.txt

>    ruby -ne 'print "#{ARGV}:#{$_}" if /black/ .. /cat/' *.txt

> --
> Nobu Nakada

Thanks,

However, the filename wasn't printed (ARGV.length = 0), so I changed it
into:

        ruby -ne 'print "#{$FILENAME}:#{$_}" if /black/ .. /cat/' *.txt

I am using ruby 1.6.7

        -- Nico --



Tue, 02 Aug 2005 19:04:33 GMT  
 How to write filesearch with begin-pattern till end-pattern
Hi,

At Fri, 14 Feb 2003 20:04:33 +0900,

Quote:

> > >  perl -ne 'print "$ARGV:$_" if /black/ .. /cat/' *.txt

> >       ruby -ne 'print "#{ARGV}:#{$_}" if /black/ .. /cat/' *.txt
> Thanks,

> However, the filename wasn't printed (ARGV.length = 0), so I changed it

Sorry, I misstyped.

        ruby -ne 'print "#{ARGF}:#{$_}" if /black/ .. /cat/' *.txt

--
Nobu Nakada



Tue, 02 Aug 2005 19:58:37 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. pattern,pattern problem

2. Pattern Definition GREP with Pattern Editing for MSDOS

3. Re-writing abstractions, or Lambda: the ultimate pattern macro

4. Re-writing abstractions, or Lambda: the ultimate pattern macro

5. Delete till end of page

6. Cals Begin and End Balance

7. prob. with BEGIN/END

8. Smalltalk on the small end (was: Advice requested: GUI project beginning)

9. /BEGIN/ .. /END/ file reading

10. begin/end doesn't behave as expected

11. Braces and begin/end

12. Suggestion for addition to Begin/End syntax

 

 
Powered by phpBB® Forum Software