Created
September 15, 2010 15:22
-
-
Save jcromartie/580882 to your computer and use it in GitHub Desktop.
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
### 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