diff options
author | Guillermo Ramos | 2012-03-29 19:33:22 +0200 |
---|---|---|
committer | Guillermo Ramos | 2012-03-29 19:39:37 +0200 |
commit | d5fc25cac083e63c88a830bdcf7359f8a1dac643 (patch) | |
tree | ab4cc595da944700d2ee0d8e9d63804b4a65ba26 /ruby/grep.rb | |
parent | 3169c1929429aa79a5dd8bee7618e4ac6f84af63 (diff) | |
download | 7l-d5fc25cac083e63c88a830bdcf7359f8a1dac643.tar.gz |
[Ruby] Día 2
Diffstat (limited to 'ruby/grep.rb')
-rwxr-xr-x | ruby/grep.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ruby/grep.rb b/ruby/grep.rb new file mode 100755 index 0000000..61d60b0 --- /dev/null +++ b/ruby/grep.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +exit 1 if ARGV.size < 2 + +pattern = ARGV[0] + +ARGV[1..-1].each do |fname| + unless File.file?(fname) + puts "File #{fname} does not exist or is a directory" + exit 1 + end + File.open(fname, 'r') do |f| + f.each_line do |line| + puts "#{f.lineno}:\t#{line}" if line =~ /#{pattern}/ + end + end +end |