dos2unix和unix2dos命令使用 - ★〓 無(wú)用的天地 〓★ - 博客大巴
版權(quán)聲明 :轉(zhuǎn)載時(shí)請(qǐng)以超鏈接形式標(biāo)明文章原始出處和作者信息及 本聲明
http://solecjj.blogbus.com/logs/19425369.html
dos2unix, unix2dos 用來(lái)實(shí)現(xiàn) DOS <=> UNIX text file 轉(zhuǎn)換
aptitude install sysutils
行末:
DOS 格式 0d 0a
UNIX 格式 0a可用功能相同的指令組合
dos2unix:
sed -i'' "s/\r//" file
或
cat file | col -b > newfile
或
cat file | tr -d "\r" > newfile
或
cat file | tr -d "\015" > newfileunix2dos:
sed -i'' "s/$/\r/" file
或
sed -i'' "s/$/\x0d/" file-i后面的是單引號(hào)組成
以上適用 GNU sed, FreeBSD 下的 sed 不適用
------------------------------------------
dos2unix 命令
這是一個(gè)很簡(jiǎn)單的命令.功能是將DOS/MAC下的文件轉(zhuǎn)化為UNIX的文本文件格式.用法詳見(jiàn)下面.
就是這樣一個(gè)簡(jiǎn)單的命令折騰了我大半天.我在用mysql查詢數(shù)據(jù)庫(kù),執(zhí)行的批處理放在了一個(gè)文件里.如果我執(zhí)行這個(gè)文件,那個(gè)存放查詢結(jié)果的 文件名字總是在后面附加一個(gè)?號(hào).而如果我一行一行敲入命令,執(zhí)行就正常.而且比較了兩個(gè)文件后沒(méi)有差別.還有一個(gè)奇怪的事情就是總是出現(xiàn)一個(gè)類似 "quit"出現(xiàn)mysql語(yǔ)法錯(cuò)誤的提示.這個(gè)奇怪的現(xiàn)象使我很困惑.后來(lái)在一位老大的幫助下想到了是不是由于文件格式的差別.因?yàn)槲疫@個(gè)文件在 windows下編輯過(guò),后來(lái)一試,果然很靈啊.
SYNOPSYS
?????? dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
?????? Options:
?????? [-hkqV] [--help] [--keepdate] [--quiet] [--version]
DESCRIPTION
?????? dos2unix, the program that converts plain
?????? text files in DOS/MAC format to UNIX format.OPTIONS
?????? The following options are available:?????? -h --help
????????????? Print online help.
?????? -k --keepdate
????????????? Keep the date stamp of output file same as input file.
?????? -q --quiet
????????????? Quiet mode. Suppress all warning and messages.
?????? -V --version
????????????? Prints version information.
?????? -c --convmode convmode
????????????? Sets conversion mode. Where convmode is one of: ASCII, 7bit,
????????????? ISO, Mac with ASCII being the default. Simulates dos2unix under
????????????? SunOS.
-o --oldfile file ...
????????????? Old file mode. Convert the file and write output to it. The pro-
????????????? gram default to run in this mode. Wildcard names may be used.
?????? -n --newfile infile outfile ...
????????????? New file mode. Convert the infile and write output to outfile.
????????????? File names must be given in pairs and wildcard names should NOT
????????????? be used or you WILL lost your files.
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.
dos2unix a.txt -c iso b.txt
?????? Convert and replace b.txt in ISO conversion mode.????????????? dos2unix -c ascii a.txt -c iso b.txt
?????? Convert c.txt from Mac to Unix ascii format.
????????????? dos2unix -c mac c.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
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
