You are not logged in.

#1 2009-11-09 13:00:02

unregistered
Member
Registered: 2008-04-09
Posts: 134

What program to convert windows txt files to linux txt and vice versa?

Any command line programs to do so? Can vim or nano convert them for me? How do I go about it?

Offline

#2 2009-11-09 13:05:42

grey
Member
From: Europe
Registered: 2007-08-23
Posts: 679

Re: What program to convert windows txt files to linux txt and vice versa?

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

#3 2009-11-09 13:33:16

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: What program to convert windows txt files to linux txt and vice versa?

or ...
tr -d '\r' <windows.txt >linux.txt

Offline

#4 2009-11-09 13:43:37

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: What program to convert windows txt files to linux txt and vice versa?

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

#5 2009-11-09 13:49:40

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 371

Re: What program to convert windows txt files to linux txt and vice versa?

Naturally, Emacs does this as well.


Arch x64 on Thinkpad X200s/W530

Offline

#6 2009-11-09 15:51:11

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: What program to convert windows txt files to linux txt and vice versa?

And sed.

Offline

#7 2009-11-10 01:36:17

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: What program to convert windows txt files to linux txt and vice versa?

tomk wrote:

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

#8 2009-11-10 01:55:43

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: What program to convert windows txt files to linux txt and vice versa?

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

#9 2009-11-10 03:35:12

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,260

Re: What program to convert windows txt files to linux txt and vice versa?

lolilolicon wrote:
Stupid question, how do you know if it works?

The only palatable way I can think of is :  od -x windows.txt

wink


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

#10 2009-11-10 03:54:09

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: What program to convert windows txt files to linux txt and vice versa?

lolilolicon wrote:

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

#11 2009-11-10 04:41:53

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: What program to convert windows txt files to linux txt and vice versa?

heh cool guys


This silver ladybug at line 28...

Offline

#12 2009-11-10 13:04:48

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: What program to convert windows txt files to linux txt and vice versa?

Hmmm - the following is _not_right:

sed 's/$/\r/'

as it would give LFCR instead of CRLF

Offline

#13 2009-11-10 13:10:00

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: What program to convert windows txt files to linux txt and vice versa?

But `file` says it is:

ASCII text, with CRLF line terminators


This silver ladybug at line 28...

Offline

#14 2009-11-10 13:24:26

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: What program to convert windows txt files to linux txt and vice versa?

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

#15 2009-11-10 15:11:10

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: What program to convert windows txt files to linux txt and vice versa?

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

#16 2009-11-10 16:49:38

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: What program to convert windows txt files to linux txt and vice versa?

*lol*
No wonder I just l-o-v-e unix/linux - where else can one have as much fun?!

Offline

Board footer

Powered by FluxBB