Forum: Ruby one-liner program example

Posted by Soichi Ishida (soichi)
on 2012-11-05 02:52
Ruby 1.9.3

I want to practice one-liner programs which are the programs written and
executed in command lines interactively.
I have no experience in Perl, so I need to do this with Ruby (or
shell-script).

Say, I have a Ruby script

  eliminate_duplication.rb

which takes one file input like

  eliminate_duplication.rb file_A.csv

Also I have the whole set of files named

  file_A.csv file_B.csv file_C.csv ...(up to Z)

Could anyone show me examples of one-liner program which apply the
script "eliminate_duplication.rb" to every file in that directory?

Thanks

soichi
Posted by Jonan S. (jonan_s)
on 2012-11-05 02:57
(Received via mailing list)
Dir.glob("*.csv").each { |f| `eliminate_duplication.rb #{f}` }
Posted by Arlen Cuss (Guest)
on 2012-11-05 02:59
(Received via mailing list)
Or at the shell:

find . -name \*.csv -exec ruby eliminate_duplication.rb '{}' \;
for i in file_[A-Z].csv; do ruby eliminate_duplication.rb $i; done
Posted by Soichi Ishida (soichi)
on 2012-11-05 03:05
Thank you so much!

soichi
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.