[ILUGC] : Tips-Learn Simple Ruby Scripting per day

  • From: ranjith.k@xxxxxxxxxxx (Ranjith)
  • Date: Tue Aug 24 16:33:19 2010

Hi,
  This script is used to remove binary (garbage) characters from a text
file.

unless ARGV.length == 1
  puts "Dude, not the right number of arguments."
  puts "Usage: ruby PrintableCharsOnly.rb YourInputFile > YourOutputFile\n"
  exit
end

file = ARGV[0]


File.readlines(file).each do |line|
  line.each_byte { |c|
      print c.chr if c==9 || c==10 || c==13 || (c > 31 && c < 127)
  }
end

-- 
Cheers,
Ranjith Kumar.K,
Software Engineer,
Sedin Technologies,

http://ranjithtenz.wordpress.com/
http://victusads.com/

Other related posts: