[lug] Seeking BASE64 Encoder
Jeff Schroeder
jeff at neobox.net
Fri Feb 11 16:28:01 MST 2005
Bill asked:
> Is there something simple that comes with RH9 that I can use to do
> this and have it run like a filter in a bash script?
Poking around my system I found /usr/bin/encode-base64, which is
apparently part of the OpenSSH installation. It's just a Perl script,
so here's the script:
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use MIME::Base64 qw(encode_base64);
my $buf = "";
while (<>) {
$buf .= $_;
if (length($buf) >= 57) {
print encode_base64(substr($buf, 0, int(length($buf) / 57) * 57,
""));
}
}
print encode_base64($buf);
It looks like I just run it with a filename to get the base64-encoded
output:
$ encode-base64 myfile.txt
Of course you could tweak the Perl to do whatever you needed as well...
HTH,
Jeff
More information about the LUG
mailing list