Closed Thread Icon

Preserved Topic: regexp fun with sed! (Page 1 of 1) Pages that link to <a href="" title="Pages that link to Preserved Topic: regexp fun with sed! (Page 1 of 1)" rel="nofollow" >Preserved Topic: regexp fun with sed! <span class="small">(Page 1 of 1)</span>\

Bipolar (III) Inmate

From: The little green dot at the center of your monitor
Insane since: Jul 2003

posted posted 02-27-2004 00:14

for file in `grep -l \(\# *`
do sed -e "s/(\(#[^\)]*\))/\<a href=\"?profiles\&do_view=1\&num_profile=\\1\"\>\(#\\1\)\<\/a\>/g" $file > $file.tmp;

that.. should change something like (#454) to <a href="?profiles&do_view=1&num_profile=454">(#454)</a>
instead it changes it to <a href="?profiles&do_view=1&num_profile=#454">(##454)</a>
any suggestions?

Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 02-27-2004 04:28

"s/(\(#[^\)]*\))/\<a href=\"?profiles\&do_view=1\&num_profile=\\1\"\>\(#\\1\)\<\/a\>/g"

You grouped the # sign with the number when you put \(#[^)]*\). Take the # out of the group and the expression should work.

use this regex:

s/(#\([^)]*\))/<a href=\"?profiles/\&do_view=1\&num_profile=\\1\">(#\\1)</a>/g

You have a lot of extrat back slants (\) in the string that I don't think are necessary. They probably don't hurt any thing but the do make the line hard to read. I dropped them out. If you need them to make the line work, put them back, but I would try the line without all the extra back slants first. The quotes (") you have around the expression should make most of them unnecessary.

-- not necessarily stoned... just beautiful.

[This message has been edited by hyperbole (edited 02-27-2004).]

« BackwardsOnwards »

Show Forum Drop Down Menu