Funny sed/reg-exp behaviour

From: David Bremer <DaveB_at_healthotago.co.nz>
Date: Sat, 22 Mar 1997 18:41:45 +1200

I've just been trying to do a simple substitution on a character in a
file to be a new line marker "\n" (the character to change was char(253)
- but this happened on attempting anything - e.g. "~!")

I had thought that a simple command like
$sed 's/~!/\\n/g' filename

Would do it. But I couldn't get the backslash in. I thought that to
substitute in a backslash you simply needed to escape it with another
backslash - but it never worked - all I ended up with was
"IN-CAPITALS-TO-SHOW-EFFECT~!BANANA" being changed to
"IN-CAPITALS-TO-SHOW-EFFECTnBANANA" (i.e. a "n" was substituted instead
of "\n"

Eventually I found that FOUR backslashes worked
$sed 's/~!/\\\\n/g' filename

"IN-CAPITALS-TO-SHOW-EFFECT\nBANANA"

Is this normal? A strange DU implimentation of sed (not likely)? or a
subtle part of escaping that I've missed (most probably)?

TIA for any enlightenment
Dave

--
Clinical Account Manager, Information Systems
Healthcare Otago (Dunedin NZ)
Ph internal: NB CHANGE 8830 
email: daveb_at_healthotago.co.nz
Pretentious quote of the week/month (whatever):
"The main things to expect when dealing with printers are troubles and
frustrations. If all else fails, just be glad its not MS-DOS". The Red
Sys-Admin Book
Received on Sat Mar 22 1997 - 07:59:31 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:36 NZDT