||[Oct. 19th, 2003|12:08 pm]
|||||REM - Hope||]|
My life would be perfect right now if I didn't have to try to learn regexp. I mean, I understand regular expressions... but actually using them in UNIX? so confusing.
But... wow. life is good.
Heh. Aren't they awfully inconsistent? Especially when you try to remember which tool wants \( \) versus ( ) for grouping. And then, if you have to worry about shell escapes, they become \\\( \\\)... ugh.
Yes. and I'm working in csh, and I tried both ( ) and \( \) and neither seemed to work... sigh.
If you don't need to use environment variables ($HOME or whatever), use single-quotes. Anything between them will not have shell substitutions applied to them.
For example (I'm using tcsh), the following:
echo "bbbaaabb" | sed -e 's/b*\(a*\)b*/\1/'
sed expects grouping operators as \( \) . ( and ) are literals.
\1 is replaced by the contents inside the first \( \) grouping (similarly for \2, \3, etc.). Hence why it printed out the "aaa".
s is the substitute command in sed; format is "s/search/replace/" or "s/search/replace/g" (where g means "global," i.e., replace all matches found, not just the first one).
You can use a character other than / to separate the parts. For example, using a comma makes it easier to type pathnames, e.g.:
sed -e 's,/home/dacut/,/home/darthparadox/,g'
will replace all occurrences of my home directory with yours.
Well, you can drop the number of escapes if you put things in quotes, at least in bash...
what's all this craziness for?