Skip to content

Instantly share code, notes, and snippets.

@carlosmcevilly
Created December 27, 2012 00:37
Show Gist options
  • Save carlosmcevilly/4384389 to your computer and use it in GitHub Desktop.
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.
#!/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