Created
June 8, 2012 01:31
-
-
Save quwubin/2892871 to your computer and use it in GitHub Desktop.
Ruby: Remove blank lines and leading ^M characters
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 | |
# | |
# Wubin Qu <[email protected]> | |
# | |
if ARGV.size != 1 | |
$stderr.puts " | |
Remove blank lines and leading ^M characters | |
Usage: | |
#{$0} file_name | |
Author: Wubin Qu <[email protected]> | |
" | |
exit | |
end | |
File.open(ARGV[0]).each_line do |line| | |
# Remove ^M when copy files from Windows | |
line.gsub!(/\r\n?/, "\n") | |
# Remove blank line | |
line.sub!(/^\n/, "") | |
next if line.size == 0 | |
$stdout.puts line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment