Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created September 15, 2010 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcromartie/580882 to your computer and use it in GitHub Desktop.
Save jcromartie/580882 to your computer and use it in GitHub Desktop.
### Ruby version ###
#!/usr/bin/ruby
File.read(ARGV[0]).split("\n").each do |line|
if line =~ /Found \d/ then
puts "=== #{line}"
end
m = /Between lines (\d+) and (\d+) in (.*)/.match line
if m then
start_line = m[1].to_i
end_line = m[2].to_i
file = m[3]
puts "--- #{line}"
puts `sed -n -e #{start_line},#{end_line}p #{file}`
end
end
### Clojure version ###
(ns dups
(:use [clojure.contrib.shell :only (sh)])
(:use [clojure.contrib.duck-streams :only (read-lines)]))
(doseq [line (read-lines (first *command-line-args*))]
(when (re-find #"Found \d" line)
(println "===" line))
(when-let [match (re-find #"Between lines (\d+) and (\d+) in (.*)" line)]
(let [[_ start end file] match]
(println "---" line)
(println (sh "sed" "-n" "-e" (str start "," end "p") file)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment