[sf-lug] Learning regular expressions, sed(1), ...

Michael Paoli Michael.Paoli at cal.berkeley.edu
Sun Feb 17 01:56:41 PST 2013


Well, regarding that example[1], I've covered some stuff on regular
expressions before, e.g. [2].  And I've certainly also covered a fair
bit on sed(1), e.g. [3].  It happens that sed fills a very interesting
niche.  Yes, sed has BREs[4][2], but notably ... well, as I've described
it before[3]:
< Useful stuff to keep in mind with sed.  It doesn't have variables.  One
< can however use the pattern space, and the hold space.  That, along with
< how those spaces can generally be manipulated and how one can deal with
< embedded newlines in those spaces, etc., that's essentially as close as
< sed comes to having variables (perhaps think of it as a pair of stacks
< or arrays).
<
< Also, sed doesn't have highly generalized flow control.  It does however
< have unconditional and limited conditional branching, and command
< grouping, and label for points branched to.
<
< So, for things approaching slightly more generalized programmatic
< (generally editing) tasks with sed, one can track state via conditionals
< and branches, and what one has in the hold and/or pattern space.

Oh, and yes, folks have actually written games in sed(1), e.g. [5].

references/excerpts/footnotes:
1. http://linuxmafia.com/pipermail/sf-lug/2013q1/009840.html
> From: jim <jim at systemateka.com>
> Date: Wed, 06 Feb 2013 09:09:45 -0800

>     I want to note to anyone learning regular
> expressions that at bottom is a really good
> sed  example.
2. http://www.rawbw.com/~mp/unix/regular_expressions/
3. news:d85eb83f.0407302303.634ae761 at posting.google.com
https://groups.google.com/forum/#!msg/comp.unix.questions/BEhuf25NVB4/lAGh9MXZ2fgJ
4. http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html
5. http://sed.sourceforge.net/#gamez





More information about the sf-lug mailing list