A Perl script I use to do this I got from the Linux Gazette (BTW this is a
great resource for Linux/Unix tricks of the trade). It may not be fast
enough for your purposes, but it works very nice. I use it all the time.
Here it is:
++++++++++++++++++++++++++++++Cut Here +++++++++++++++++++++++++++++++
#!/usr/bin/perl -wpi.bak
#
# Simpler unix2dos2mac utility for 2-cent tip, mainly because Tcl is ugly.
# No comments that Perl is ugly too, please.
#
# d2u - converts from text files from dos to unix or mac and back.
# Create symbolic links to d2u representing the other conversions you want.
# e.g. ln -s d2u u2d (for unix to dos conversion)
#
# d2u - dos to unix
# u2d - unix to dos
# u2m - unix to mac
# m2u - mac to unix
# d2m - dos to mac
# m2d - mac to dos
#
# Usage: a standard Unix filter:
# input: filename(s) or stdin
# output: source file (back-up to .bak file)
# To direct output to stdout replace -wpi.bak with -wp on first line.
# Buglet: u2m leaves lone CR at the end of file if it didn't end in LF
# (Fixing it would use more memory.)
BEGIN {
$_=$0 =~ s|.*/||;
$pcmd='s/$/\r/' if ($0 eq 'u2d');
$pcmd='s/\r$//' if ($0 eq 'd2u');
$pcmd='s/$/\r/;chop' if ($0 eq 'u2m');
$pcmd='s/\r/\n/g' if ($0 eq 'm2u');
$pcmd='chomp' if ($0 eq 'd2m');
$pcmd='s/\r/\r\n/g' if ($0 eq 'm2d');
unless($pcmd) {
print STDERR "This script must be invoked under one of the names:\n",
" u2d, d2u, u2m, m2u, d2m, m2d\n";
exit 1;
}
}
eval $pcmd;
++++++++++++++++++++++++++ Cut Here ++++++++++++++++++++++++++++++++++++
Dan Browning wrote:
> What utils are available (preferable ones that use STDIN, STDOUT, and
> STDERR) to convert unix text files to DOS (win,etc.) text files and back?
> Written in C, and can process gigabytes of small text files fast?
>
> Dan Browning
> Network Administrator
> Cyclone Computer Systems
--
Robert B. Haehnel
Ice Engineering Research Division
Cold Regions Research and Engineering Laboratory
72 Lyme Road
Hanover, NH 03755-1290
Phone: (603)646-4325
Fax: (603)646-4477
e-mail: [EMAIL PROTECTED]
web: http://www.crrel.usace.army.mil