Skip to content

Converting pc files to unix

3 messages · Hai Lin, Uwe Ligges, Constantinos Antoniou

#
Hai Lin wrote:

            
It should work, at once, given you have not used Windows specific 
commands, hard coded paths etc...

Uwe Ligges
#
On 4 ?????? 2005, at 11:41 ????, Uwe Ligges wrote:

            
Hai,

On the mac, try to open the files in a "unixy" editor, such as emacs, 
pico, vi. If your file looks something like this (look for ^M):

first line of R commands^Msecond line of R commands^Metc

then the problem is line endings (that are different between platforms).

To fix this, you can open the file(s) in an editor, e.g. SubEthaEdit 
(free for personal and educational use) and then change the line 
endings (Format->Line endings->Convert to unix line endings..)

Another approach (useful if you want to batch-convert a lot of files) 
is to run a script like this:

  #!/bin/sh
     tr '\r' '\n' < $1 >MKTMP001
     mv -f MKTMP001 $1

You can save this as a file, e.g. call it stripCtrlM, make it 
executable (chmod +x stripCtrlM) and run it:

stripCtrlM filesWithCtrlM.R

or stripCtrlM *.R to convert all .R files in a directory

Hope this helps,

Costas