Created
December 27, 2012 00:37
-
-
Save carlosmcevilly/4384389 to your computer and use it in GitHub Desktop.
cat a file, removing leading and trailing space, removing
empty lines, and ensuring every line is followed by a newline.
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/local/bin/perl | |
# cat a file, removing leading and trailing space, removing | |
# empty lines, and ensuring every line is followed by a newline. | |
use strict; | |
use warnings; | |
my $line; | |
while (defined($line=<>)) { | |
$line =~ s/[\n\r\f]+$//g; | |
$line =~ s/^\s+//; | |
$line =~ s/\s+$//; | |
next if ($line =~ /^\s*(\#.*)?$/); # skip comments & blank lines | |
print "$line\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment