OT : how do you remove blank lines ?

  • Thread starter Thread starter Laurent Herve
  • Start date Start date
L

Laurent Herve

Ok i could remove them with gbtext, or with grep, but with
wordpad, or with a hex editor ? isn't a new line \n\r ? but when
i type in an editor i get it litterally (gasp !) Alt 13 is a new line,
but what is the point with \n, \r ? sorry for being confusing,
i hope someone could shed light on that ;

thanks,

laurent
 
Ok i could remove them with gbtext, or with grep, but with
wordpad, or with a hex editor ? isn't a new line \n\r ? but when
i type in an editor i get it litterally (gasp !) Alt 13 is a new line,
but what is the point with \n, \r ? sorry for being confusing,
i hope someone could shed light on that ;

You can't search/replace new line characters in WordPad. This is just
not implemented.

To understand the origin and meaning of \r\n you have to recall the
working of good old typewriters. You type a sequence of keys. At the
end of the line you can hit a key to get back to the beginning of this
*same* line. (Starting to overwrite every single char just written.)
This is what's called 'carriage return'.

Or you can just draw a wheel on the typewriter to get to the next line
('new line'). In that case you would continue writing just below the
character space following the last finished char of the former line.

In most cases you'd need to combine both key sequences to achieve what
you really want. - Of course: Most type writers have an extra key for
this combination... ;-)

Early computers supported an output mode called (tele)typewriter mode.
(Modern ones still do, of course.)

You can think of it as a (seemingly endless) stream of characters.
To mark sequences, ring a bell or delete a formerly sent (wrong)
character, ... formatting codes are inserted in such streams. Every
character is encoded as a sequence of current/no current. (Often 7
or 8 'bit'.) The mentioned control characters usually got very early
positions in the tables to built these characters. Look at an ASCII
chart and you'll find 'start of text' / 'end of text' / 'bell' / ...
on the first 32 positions. Among them are 'carriage return' (at the
position 14 with a value of 13 - counting starts with 0!) and 'line
feed' (at position 11 with value 10).

As on a typewriter you'll find different solutions to get to the
beginning of a new line with different operating systems (and
sometimes with different programs). While in *nix systems most lines
just end with a 'new line' control char, you'll see a sequence of
'carriage return','line feed' in most DOS/Win texts, and 'carriage
return' in classic Mac texts.

You mentioned hex editors yourself. If you scan with one of these
through your text you'll see every sentence finished with one of the
above combinations: 0Dh (= 13 decimal ... 'carriage return') and
0Ah (= 10 decimal ... ' line feed') for DOS texts, for instance.

These characters are normally not displayed inside a text editor.
It's the task of a text editor to *interpret* these chars. That's
why it just prints the following text on the next line. Because
of their special treading all control chars often need special
methods for input. You mentioned Alt+13. That just inserts a char
of ASCII value 13 (decimal) inside most Windows application. It
is the 'carriage return' char.

Another way is to refer to them via escape sequences. These are
predefined character combinations to be interpreted in a different
way. The sequence \n for instance stands for 'new line'. You find
these sequences mostly in programs supporting (maybe a subset) of
so-called regular expressions. You mentioned grep which is a good
example.

To sum up:
Use WordPad for simple text viewing / editing. But switch to a
more powerful program if you which to replace empty lines by
other means than by hand.

You see a bit of dawn now? ;-)

BeAr
 
Back
Top