[svlug] text files on Mac's, Windoze, and Linux
Castrol
castrol at 3am.de
Mon Jul 17 15:19:01 PDT 2000
Seth David Schoen wrote:
> Gordon Vrololjak writes:
>
> > Excuse my ignorance, but is there a utility in linux for changing text
> > files formatting from various os's into linux's? Sorry if this is covered
> > in the Unix faq, but I couldn't see it there.
>
>
> Converting to DOS format is more annoying, but it's still a trivial
> one-line Perl or C program. From Unix, you need to replace "\n" by
> "\r\n"; from Mac, you need to replace "\r" by "\r\n".
>
> DOS EOL is CRLF ("\r\n"); Unix EOL is LF ("\n"); Mac EOL is CR ("\r").
>
> Some Unixes have a C program called fromdos/todos if (like me) you
> don't remember enough Perl to write that one-liner to convert to DOS
> format.
#!/usr/bin/perl
print("initialising variables...");
$dos="\r\n";
$unix="\n";
$mac="\r";
print (" done.\n");
sub printUSAGE
{
print("quick-and-dirty file converter v0.9 alpha\n");
print("ERROR: please give filename as first argument!\n");
print("Try \"this_script.pl >> test.text\"\n");
}
sub getFile
{
print ("getting file...");
open (INFILE, "<$_[0]");
return <INFILE>;
close (INFILE);
print(" done.\n");
}
if ($ARGV[0] eq "")
{
&printUSAGE();
die;
}
if (-e ARGV[0])
{
print("quick-and-dirty file converter v0.9 alpha\n");
print("ERROR: sorry, file doesn't exist...\n");
}
else
{
@file=&getFile($ARGV[0]);
print ("starting substitution...");
foreach $line(@file)
{
$line=~s/$dos/$unix/go;
} # the actual one-liner!! :)
# first item is the OS you got the file from
# second one the OS you want to convert to
print(" done.\n");
}
print @file;
# dunno if this works but it should..
# I don't actually have files originating from other OS'es
broesel
broesel at 3am.de
More information about the svlug
mailing list