[clue] Piping, xargs, find, grep and such

jacob jborer at gmail.com
Sun Sep 16 20:55:02 MDT 2012


Change the ruby script. Ruby has a var that defines the name of the current
file (ARGF.filename) and you can just do something like,

puts "#{ARGF.filename}:#{output}" if output =~ /pattern/

Jacon
On Sep 16, 2012 5:30 PM, "David L. Anselmi" <anselmi at anselmi.us> wrote:

> Sean LeBlanc wrote:
> > I have a Ruby script that takes as input either:
> >
> > 1. 1-N command line args, assumes those are filenames, and iterates over
> > those, translating the files into a readable format - writing on STDOUT.
> > 2. If no args, read STDIN and do the same with that stream of data.
> >
> > find . -name * -print | xargs ./myscript.rb | grep "asearchstring"
> >
> > And that's all well and good. Now, I want to know what file(s) I get a
> > hit in.
>
> Since you don't seem to care that all the inputs go to the same output you
> could prepend each line
> with the file name.
>
> Your script could send each file name to stderr before processing it.
>  That only really works for
> screen output and isn't the Unix Way.
>
> Your script could send each file name to stdout before processing it and
> then your grep could
> include something that works on the file name lines:
>   ... | egrep "(file:|asearchstring)"
>
> Your script could produce an output file for each input file and then grep
> would work as usual (then
> to pipe to it you'd write the file names to stdout and go through xargs
> again).
>
> HTH,
> Dave
> _______________________________________________
> clue mailing list: clue at cluedenver.org
> For information, account preferences, or to unsubscribe see:
> http://cluedenver.org/mailman/listinfo/clue
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cluedenver.org/pipermail/clue/attachments/20120916/d75db415/attachment.html 


More information about the clue mailing list