+ -
当前位置:首页 → 问答吧 → 怎样把LF换成CRLF

怎样把LF换成CRLF

时间:2011-04-25

来源:互联网

本帖最后由 liion631818 于 2011-04-25 12:13 编辑

从linux下拷贝下的文件每行都以LF结束,怎样把LF换成CRLF呢,这样在windows下用记事本打开的时候显示就正常了

可以用sed写一个吗?或者其他方法也可以。

作者: liion631818   发布时间: 2011-04-25

unix2dos

作者: ywlscpl   发布时间: 2011-04-25

直接在win下面用写字板打开另存一下吧

作者: waker   发布时间: 2011-04-25

回复 ywlscpl


    这个倒是可以哦,只是最近看sed,是否有办法可以匹配LF呢???然后换成LFCR

作者: liion631818   发布时间: 2011-04-25

本帖最后由 yinyuemi 于 2011-04-25 11:36 编辑

回复 liion631818
  1. sed -i 's/$/^M/g'  file
复制代码

作者: yinyuemi   发布时间: 2011-04-25

将乱格式(unix,mac,dos或杂交格式)转换为dos:
  1. s/\r$//
  2. s/\r/\r\n/g
  3. s/$/\r/
复制代码

作者: blackold   发布时间: 2011-04-25

CRLF

作者: ziyunfei   发布时间: 2011-04-25

回复 ziyunfei


    多谢指正,看来细节还是要注意的哦,谢谢了

作者: liion631818   发布时间: 2011-04-25

回复 yinyuemi


    好像不可以啊,我是在windows下用的sed.exe
   按照你的命令,替换之后XXXXXXXXXXXXXXXXXX^M这样了
   $匹配行的结束,不能匹配到LF吧????

作者: liion631818   发布时间: 2011-04-25

回复 blackold


    s/\r/\r\n/ 不行啊.

作者: liion631818   发布时间: 2011-04-25

回复 liion631818


    ^M = Ctrl+v +m

作者: yinyuemi   发布时间: 2011-04-25

回复 yinyuemi


    哦,这样可以了。谢谢了哦
   ^M这样的输入怎样就变成\n了。可以介绍相关资料看看吗?

作者: liion631818   发布时间: 2011-04-25

回复 liion631818


    google下吧,我手头没有现成的,不好意思:em06:

作者: yinyuemi   发布时间: 2011-04-25

本帖最后由 yinyuemi 于 2011-04-25 14:02 编辑

回复 liion631818

Control Characters
Char Oct Dec Hex Control-Key Control Action
NUL 0 0 0 ^@ Null character
SOH 1 1 1 ^A Start of heading, = console interrupt
STX 2 2 2 ^B Start of text, maintenance mode on HP console
ETX 3 3 3 ^C End of text
EOT 4 4 4 ^D End of transmission, not the same as ETB
ENQ 5 5 5 ^E Enquiry, goes with ACK; old HP flow control
ACK 6 6 6 ^F Acknowledge, clears ENQ logon hand
BEL 7 7 7 ^G Bell, rings the bell...
BS 10 8 8 ^H Backspace, works on HP terminals/computers
HT 11 9 9 ^I Horizontal tab, move to next tab stop
LF 12 10 a ^J Line Feed
VT 13 11 b ^K Vertical tab
FF 14 12 c ^L Form Feed, page eject
CR 15 13 d ^M Carriage Return
SO 16 14 e ^N Shift Out, alternate character set
SI 17 15 f ^O Shift In, resume defaultn character set
DLE 20 16 10 ^P Data link escape
DC1 21 17 11 ^Q XON, with XOFF to pause listings; ":okay to send".
DC2 22 18 12 ^R Device control 2, block-mode flow control
DC3 23 19 13 ^S XOFF, with XON is TERM=18 flow control
DC4 24 20 14 ^T Device control 4
NAK 25 21 15 ^U Negative acknowledge
SYN 26 22 16 ^V Synchronous idle
ETB 27 23 17 ^W End transmission block, not the same as EOT
CAN 30 24 17 ^X Cancel line, MPE echoes !!!
EM 31 25 19 ^Y End of medium, Control-Y interrupt
SUB 32 26 1a ^Z Substitute
ESC 33 27 1b ^[ Escape, next character is not echoed
FS 34 28 1c ^\ File separator
GS 35 29 1d ^] Group separator
RS 36 30 1e ^^ Record separator, block-mode terminator
US 37 31 1f ^_ Unit separator

作者: yinyuemi   发布时间: 2011-04-25