euglug.org

Resolved: [Eug-lug] Source Code Processing

작성자

카테고리:



horstThu May 5 19:39:51 PDT 2005

> Date: Thu, 5 May 2005 14:58:01 -0700
> From: Jason Van Cleve <jason at vancleve.com>
..>
> Actually, the DOS newlines themselves were not my problem, and I didn't
> <i>want</i> to change them necessarily.  It was that they were confusing
> sed so that my regular expression didn't work.  To my simple mind, DOS
> newlines are newlines too, and so "$" should match them.  Unless it is

"$" is the end of line (text line as I understand it, before the 'newline' 
char(s)
The casual term 'newline' has different meanings on different OSes.
On nix it's 0A	(hex, i.e 10 decimal)
On DOS it's 0D 0A  (2 bytes, 13 and 10)
On Mac it's 0D

Of course, above bytes have conventional names NL and CR as you maybe able 
to see when you run 'man ascii' , but the newline '\n' used in programming 
languages, and some shell programs is just a symbol that is translated 
according to the OS. As I recall that holds for C++ and java. But I am 
sure in python, as the one line below yield different files 'test' , 3 
bytes on nix, 4 bytes on DOS:
  python -c "fout = open('test', 'w') ; fout.write('Hi\n') ; fout.close()"

So if I *want* to preserve the individual OS-style newline with a mix of 
files I'd use a programming language, in my case python, and handle the 
'0A' and 'OD' directly (w/o '\n' translation).

  - Horst, in vi ^M is ctrl-v ctrl-m.