[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Apologies for long line length and a newline problem



And Lo! The Great Prophet Lesley Anne Binks uttered these words of wisdom:
>
> Now in Windows 0x0D 0x0A is the carriage return line feed
> and on Linux boxes I've always understood it's 0x0D only.
> Emacs showed the  newlines not as newlines but as ^M 
> which translates to 0x0D.  Obviously this caused problems on 
> a search and replace.

Linux (and UNIX in general) lines end with a linefeed -- LF (0x0A). If 
you're used to using text files on a mac, then text files there end in CR
(0x0D) only. Microsoft does (arguably) the right thing treating CR and LF
as two copletely seperate functions.

However arguing about that is beyond the scope of this email :-)

> Anyone else come up against this kind of problem ? What's 
> the fix, bar going through the extracted text files and 
> making the relevant replacements by hand?

In ksh/sh/bash, this will process /all/ files in the current directory.

	for i in *
	do
		if [ -f $i ]; then
			mv $i /tmp/workfile
			tr -d '\r' < /tmp/workfile > $i
		fi
	done

should do the job (untested). There may be a way to do it in perl using its 
in-line editing (so you don't need to make a temporary file), but I'll 
leave that for the perl monks.

Chris...

-- 
\ Chris Johnson                 \ NP: 
 \ cej [at] nightwolf.org.uk          \  
  \ http://cej.nightwolf.org.uk/  \ 
   \ http://redclaw.org.uk/        ~---------------------------------------


___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.