Created
June 11, 2009 07:34
-
-
Save sousk/127760 to your computer and use it in GitHub Desktop.
snip out large text file with regexp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
path, from, to = $* | |
unless path && from && to | |
puts <<-__DESCRIPTION__ | |
./echo_between.rb file_path "from" "to" | |
snips large text file | |
command starts to print lines when matched "from" | |
and stops when matched "to" | |
__DESCRIPTION__ | |
exit(1) | |
end | |
switched = false | |
File.open(path, 'r').each do |line| | |
switched = true if line.match(/#{from}/) | |
if switched && line.match(/#{to}/) | |
puts "end with line: #{line}" | |
exit(0) | |
end | |
puts line if switched | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment