On Mon, 03 Dec 2012 03:04:45 +0100, Clark WANG <[email protected]> wrote:
On Mon, Dec 3, 2012 at 3:37 AM, j. v. d. hoff
<[email protected]>wrote:
hi,
I'm currently trying to set up a `ksh' script as a drop in replacement
for
`awk' in processing some text. I've stumbled over the following.
consider this string:
a="water: h~2~^o^ and ammonia: NH~3~"
where I want to replace the `~' enclosed text parts by something else,
maintaining the enclosed text. I've tried
echo "${a/~(-g:~(*)~)/#\1#}"
to replace the first hit in the line by `h#2#'
but this does not work (neither does the same with backquoted `~').
what am I missing? something to do with tilde expansion?
[STEP 100] $ echo ${.sh.version}
Version AJMP 93u+ 2012-08-01
[STEP 101] $ a="water: h~2~^o^ and ammonia: NH~3~"
[STEP 102] $ echo "${a/@-(~@(*)~)/#\2#}"
water: h#2#^o^ and ammonia: NH~3~
[STEP 103] $ echo "${a//@-(~@(*)~)/#\2#}"
water: h#2#^o^ and ammonia: NH#3#
[STEP 104] $
thanks a lot, that's exactly what I need. I'll use that one. I'm more at
home with standard regex, so I don't quite understand what the pattern is
doing: especially
the leading `-' in front of the "core pattern". what does
`-(pattern-list)' mean? I see it makes the pattern non-greedy, but I don't
find it in the manpage (or the book).
but regarding my own, failed, attempt at a solution: why is
echo "${a//~(-g:~(*)~)/#\1#}"
_not_ doing the intended? if I read the manpage correctly, it should. and
echo "${a//~(-g:^(*)^)/#\1#}"
indeed _does_ replace the `^' characters enclosing the `o' in the example
string $a. only after your answer I've tried
echo "${a//~(-g:~@(*)~)/#\1#}"
why do I need the "exactly one" `@' qualifier for `(*)' here (and in your
solution) when the enclosing characters are `~' (but not, e.g., `^')?
I suspect it has something to do with the `~' being special but I don't
see why and how.
j.
thanks
joerg
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
______________________________**_________________
ast-users mailing list
[email protected].**com <[email protected]>
http://lists.research.att.com/**mailman/listinfo/ast-users<http://lists.research.att.com/mailman/listinfo/ast-users>
--
Using Opera's revolutionary email client: http://www.opera.com/mail/
_______________________________________________
ast-users mailing list
[email protected]
http://lists.research.att.com/mailman/listinfo/ast-users