ruby_grep¶ ↑
Module to search file(s) for lines that match a given pattern. It (will) implements full functionality of the “grep” command in Unix/Linux system with Ruby. Specification goes to www.opengroup.org/onlinepubs/9699919799/utilities/grep.html.
Note on Patches/Pull Requests¶ ↑
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history.(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Install¶ ↑
$ gem install ruby_grep
Examples¶ ↑
require 'ruby_grep' # grep content in a file file = File.open(file_path) file.grep(/example/, {:recursive => false}) do |path, line| puts "#{path}: #{line}" end # grep content by recursively traversing a folder File.grep(folder_path, 'example', {:recursive => true}).each do |match| puts "#{match.path}: #{match.line}" # match is a Struct object with path and line as attributes end
Copyright¶ ↑
Copyright © 2010 Jingwen Owen Ou. See LICENSE for details.