现在的位置: 首页 > 综合 > 正文

dos和unix文本转化

2017年12月09日 ⁄ 综合 ⁄ 共 2238字 ⁄ 字号 评论关闭

一 unix/linux 命令

 

unix2dos - UNIX to DOS text file format converter  

 

EXAMPLES

Get input from stdin and write output to stdout.

unix2dos

Convert and replace a.txt. Convert and replace b.txt.

unix2dos a.txt b.txt
unix2dos -o a.txt b.txt

Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode.

unix2dos a.txt -c iso b.txt
unix2dos -c ascii a.txt -c iso b.txt

Convert and replace a.txt while keeping original date stamp.

unix2dos -k a.txt
unix2dos -k -o a.txt

Convert a.txt and write to e.txt.

unix2dos -n a.txt e.txt

Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt.

unix2dos -k -n a.txt e.txt

Convert and replace a.txt. Convert b.txt and write to e.txt.

unix2dos a.txt -n b.txt e.txt
unix2dos -o a.txt -n b.txt e.txt

Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt.

unix2dos -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt

dos2unix - DOS/MAC to UNIX text file format converter

 

 

EXAMPLES

Get input from stdin and write output to stdout.

dos2unix

Convert and replace a.txt. Convert and replace b.txt.

dos2unix a.txt b.txt
dos2unix -o a.txt b.txt

Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. Convert c.txt from Mac to Unix ascii format.

dos2unix a.txt -c iso b.txt
dos2unix -c ascii a.txt -c iso b.txt
dos2unix -c mac a.txt b.txt

Convert and replace a.txt while keeping original date stamp.

dos2unix -k a.txt
dos2unix -k -o a.txt

Convert a.txt and write to e.txt.

dos2unix -n a.txt e.txt

Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt.

dos2unix -k -n a.txt e.txt

Convert and replace a.txt. Convert b.txt and write to e.txt.

dos2unix a.txt -n b.txt e.txt
dos2unix -o a.txt -n b.txt e.txt

Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt.

dos2unix -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt

 

 二 perl脚本

dos2unix.pl

my $file = shift;

if (-$file)
{
  
open IN, "< $file";
  
@DOSFILE = <IN>;
  
close IN;
  
chomp @DOSFILE;
}
else
{
  
print "$file is NOT writable\n";
  
exit 1;
}

open OUT, "> $file";
binmode OUT;

foreach (@DOSFILE)
{
  
print OUT $_;
  
print OUT "\012";
}

close OUT;

 

 unix2dos.pl

 


my $file = shift;

if (-$file)
{
  
open IN, "< $file";
  
@DOSFILE = <IN>;
  
close IN;
  
chomp @DOSFILE;
}
else
{
  
print "$file is NOT writable\n";
  
exit 1;
}

open OUT, "> $file";
binmode OUT;

foreach (@DOSFILE)
{
  
print OUT $_;
  
print OUT "\r\n";
}

close OUT;

 

三 其他工具Tofrodos

 http://www.thefreecountry.com/tofrodos/index.shtml

 

完!

抱歉!评论已关闭.