Skip to content

Instantly share code, notes, and snippets.

@sousk
Created June 11, 2009 07:34
Show Gist options
  • Save sousk/127760 to your computer and use it in GitHub Desktop.
Save sousk/127760 to your computer and use it in GitHub Desktop.
snip out large text file with regexp
#!/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