From: Andrew Timberlake Date: 2009-01-13T00:28:14+09:00 Subject: Re: Data stream variables ------=_Part_331054_12865720.1231774135320 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jan 12, 2009 at 4:45 PM, Alain Helfenstein wrote: > Andrew Timberlake wrote: > > On Mon, Jan 12, 2009 at 3:21 PM, Alain Helfenstein > > >> wrote: > > > >> first file of '*.xml' > >> > >> ruby -n -e 'puts ($FILENAME + " " + $..to_s + "" + $_) if /Open/' *.xml > >> > >> Does anybody have a idea, on how to print the correct line number? > >> > >> Thanks a lot for your answer, Alain. > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > Does it all have to be done in ruby? > > Why not > > ls *.xml | xargs ruby -n -e 'puts ($FILENAME + " " + $..to_s + "" + $_) > > if > > /Open/' > > > > -- > > Andrew Timberlake > > http://ramblingsonrails.com > > http://www.linkedin.com/in/andrewtimberlake > > > > "I have never let my schooling interfere with my education" - Mark Twain > > Thanks a lot for your answer. > > Sadly I'm running Windows XP. > > But I try to get GnuWin32 running... > > Alain > -- > Posted via http://www.ruby-forum.com/. > > Alain Sorry, I made a mistake with my answer above. Instead of using xargs (which was exactly the same as your method - actually) Use find to make sure ruby gets a unique file each time: find *.xml -exec ruby -n -e 'puts ($FILENAME + " " + $..to_s + "" + $_) if /Open/' {} \; --still doesn't help on Windows though Instead of trying to do this in a one-liner, save the following as a file: ARGV.each do |filename| File.open(File.join(File.dirname(__FILE__), filename)) do |file| while line = file.gets puts (filename + " " + $..to_s + "" + $_) if line =~ /Open/ end end end And then run: ruby *.xml Hopefully that helps -- Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain ------=_Part_331054_12865720.1231774135320--