Created
September 27, 2013 14:48
-
-
Save stanBienaives/6729778 to your computer and use it in GitHub Desktop.
Simple ruby script to spot encoding errors on a given in params.
This file contains 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 | |
file = ARGV.first | |
count = %x( wc -l #{file}).split.first.to_i | |
puts "Number of line in the file: #{count}" | |
min = 0 | |
max = count | |
while max - min > 2 | |
n = (max + min)/2 | |
%x( tail -n +#{n} #{file} > tmp) | |
error = %x( file --mime tmp).gsub(/.*charset=([^ ]*).*/, '\1').chomp == 'binary' | |
puts "#{n}" | |
error ? min = n : max = n | |
end | |
puts "" | |
if n > 1 | |
puts "Error spotted on line: #{n}" | |
puts "" | |
puts "Run this script again to spot mode encoding errors" | |
else | |
puts "no errors spotted" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment