Skip to content

Instantly share code, notes, and snippets.

@vStone
Created August 3, 2012 09:18
Show Gist options
  • Save vStone/3246220 to your computer and use it in GitHub Desktop.
Save vStone/3246220 to your computer and use it in GitHub Desktop.
Perl script to strip newline at end of files.
#!/usr/bin/perl
## Strips the newline from the end of a file.
# This is important because we cant have newlines after the pw hash.
# Run this on a file before committing.
use autodie qw(open sysseek sysread truncate);
my $file = shift;
open my $fh, '+>>', $file;
my $pos = tell $fh;
sysseek $fh, $pos - 1, 0;
sysread $fh, my $buf, 1 or die 'No data to read?';
if($buf eq "\n"){
truncate $fh, $pos - 1;
}
@rtoma
Copy link

rtoma commented Feb 6, 2013

Or use 'echo -n "XXXX"'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment