Other *NIXThis forum is for the discussion of any UNIX platform that does not have its own forum. Examples would include HP-UX, IRIX, Darwin, Tru64 and OS X.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Sed Regular Expressions
The regular expressions used in sed, by default, are basic regular
expressions (BREs, see re_format(7) for more information), but extended
(modern) regular expressions can be used instead if the -E flag is given.
In addition, sed has the following two additions to regular expressions:
1. In a context address, any character other than a backslash (``\'')
or newline character may be used to delimit the regular expression.
Also, putting a backslash character before the delimiting character
causes the character to be treated literally. For example, in the
context address \xabc\xdefx, the RE delimiter is an ``x'' and the
second ``x'' stands for itself, so that the regular expression is
2. The escape sequence \n matches a newline character embedded in the
pattern space. You can't, however, use a literal newline character
in an address or in the substitute command.
Try your first example in Linux using single quotes or use a sed script. I'm not at my Linux computer now so I can't try it.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Solaris treats the \n in sed the same as HP/UX.
I learned sed and have always used it as an editor that works within individual lines within files. ^ and $ delimit the beginning and end of lines; but, for example, 's/^18//g' just removes the 18 from the beginning of the line, it does not remove the beginning of the line.
The Gnu/Linux example is probably an extension of the tradional functionality.
I just jump to other tools when one doesn't quite do it -- grep, tr, sed, awk, sort, uniq, etc. and then on to perl snippets. Although I agree it can be annoying when a really simple solution turns out not to be.