Line Breaks

Don MacQueen macq at llnl.gov
Mon Jun 30 21:48:39 CEST 2003


Emcas can be a little slow at this kind of global replacement. For a 
small file, no problem, of course, but I sometimes have very large 
files.

Instead, I have a little shell script I routinely use to deal with 
this kind of problem. The crucial line is the one that uses the "tr" 
command. As shown below, it is set up to translate Mac end-of-line 
characters to unix end-of-line characters; you'd have to change it 
slightly for dos to unix. Mac end-of-line characters are what you 
will get if, for example, you save an Excel spreadsheet as text in 
Mac OS X.

Put the script somewhere in your PATH, make it executable. Use the 
'rehash' command to tell the OS there's something new in the path.

Then type "scriptname filename" at the unix prompt, where filename is 
the name of one of your .ssc files.

#! /bin/csh -f
echo Lines before: `wc -l $1`
setenv tmpfl tmp`echo $$`
# echo temp file name $tmpfl
mv $1 $tmpfl
tr '\015' '\n' < $tmpfl > $1
echo Lines after `wc -l $1`
## should test for successful return from tr before removing temp file
rm $tmpfl
echo Done

I should mention this script has been criticized many times as crude 
and ugly. That it is. Indeed, the same job can be done just as easily 
with a perl one-liner.

-Don

At 11:30 AM -0400 6/26/03, bb2 at duke.edu wrote:
>Hi All,
>
>I've recently migrated from Splus 2000 (Windows) to R on Mac OSX. 
>In the process, I've begun using Xemacs and ESS to work in R.  As a 
>result, I have moved my old .ssc files to this new environment 
>(burned them to a cd and moved them onto my new computer).  When I 
>open the .ssc files in Xemacs, there is a "^M" at the end of each 
>line.  I can scroll through the file deleting each "^M" but this is 
>very slow.
>
>How can I easily remove these with Xemacs or avoid the entire 
>problem to begin with?
>
>Similarly, I use winBugs on Virtual Windows and when I paste text 
>from winBugs into Xemacs (running on OSX), I have the same problem.
>
>Any suggestions would be appreciated.
>
>Thanks for your help,
>Brian
>
>______________________________________________
>ESS-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/ess-help


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the ESS-help mailing list