You are not logged in.
Any command line programs to do so? Can vim or nano convert them for me? How do I go about it?
Offline
The package is called hd2u, the command is dos2unix. Despite its name it converts both ways. No man page, but --help works.
Good ideas do not need lots of lies told about them in order to gain public acceptance.
Offline
or ...
tr -d '\r' <windows.txt >linux.txt
Offline
Vim can do so. :set fileformat=dos and save, or :set fileformat=unix and save to go the other way. Not for converting many files at once, but handy to know.
Offline
Naturally, Emacs does this as well.
Arch x64 on Thinkpad X200s/W530
Offline
And sed.
Offline
And sed.
Ya know - I _was_ going to say that as well, but then I tried a
sed -e 's/\n/\r\n/
and that didn't work ... I guess '\r' and '\n' are not sed regex - I didn't follow it any further ...
'sed oneliners' would probably have given me the right syntax ...
Offline
Does this work?
sed 's/\x0D$//' #dos -> unix
sed 's/$/\r/' #unix -> dos
Stupid question, how do you know if it works?
This silver ladybug at line 28...
Offline
lolilolicon wrote:
Stupid question, how do you know if it works?
The only palatable way I can think of is : od -x windows.txt
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Stupid question, how do you know if it works?
> file dos.txt
dos.txt: ASCII English text, with CRLF line terminators
> tr -d '\r' < dos.txt > unix.txt
> file unix.txt
unix.txt: ASCII English text
How it knew it is English, I have no idea.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
heh cool guys
This silver ladybug at line 28...
Offline
Hmmm - the following is _not_right:
sed 's/$/\r/'
as it would give LFCR instead of CRLF
Offline
But `file` says it is:
ASCII text, with CRLF line terminators
This silver ladybug at line 28...
Offline
Yes, but the 'original' was a dos-file, then he used "tr -d '\r'" to make it into a linux file ...
Ahhh - I've just tried it out (sed 's/$/\r/') and for some strange reason, it _does_ give CRLF (never mind what 'file' says - the only way you can be 100% sure is doing a 'od -a').
OK, it does make some kind of sense (I guess). '$' is the end of the line - ie immediately prior to LF, so what it is actually doing is inserting a CR infront of the NL ... got it now!
And that's why my previous attempt didn't work - 'sed' kinda strips off the NL saying "this is where the line ends" and then when it writes out the record/line again, it adds the line terminator (NL) to the record.
Last edited by perbh (2009-11-10 13:27:24)
Offline
Yup, exactly. sed is not a binary stream editor (though you still can).
Edit: Curiosity got the better of me:
> file dos.txt
dos.txt: ASCII text, with CRLF line terminators
> od -a dos.txt
0000000 d o s sp l i n e sp 1 cr nl d o s sp
0000020 l i n e sp 2 cr nl
0000030
> cat dos.txt | sed ':a;N;s/\r\n/\n\r/;ta' > flip.txt
> od -a flip.txt
0000000 d o s sp l i n e sp 1 nl cr d o s sp
0000020 l i n e sp 2 cr nl
0000030
> file flip.txt
flip.txt: ASCII text, with CRLF, CR, LF line terminators
Edit 2: Yes, I noticed that. I'm fixing it.
Edit 3: tr is still the man. Bad sed, no cookie:
> file dos.txt
dos.txt: ASCII text, with CRLF line terminators
> od -a dos.txt
0000000 d o s sp l i n e sp 1 cr nl d o s sp
0000020 l i n e sp 2 cr nl
0000030
> cat dos.txt | tr '\r\n' '\n\r' > flip.txt
> od -a flip.txt
0000000 d o s sp l i n e sp 1 nl cr d o s sp
0000020 l i n e sp 2 nl cr
0000030
> file flip.txt
flip.txt: ASCII text, with CR, LF line terminators
The other edit kept for posterity.
Last edited by fsckd (2009-11-10 15:43:03)
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
*lol*
No wonder I just l-o-v-e unix/linux - where else can one have as much fun?!
Offline