[plug] Scripting Help - Search, Mangle, Replace

Jason Nicholls jason at mindsocket.com.au
Fri Jun 22 18:51:15 WST 2007


On Fri, Jun 22, 2007 at 08:07:07PM +1000, Timothy White wrote:
> I have some interesting scripting I'm trying to do, and wish to avoid
> Perl/PHP and the more complex languages.
> 
> Basically, I have a document that has a number of occurences of
> <U>Some text</U> and I wish to search for all occurences, and remove
> the <U> tags, and append to the end of it, the output of a "command"
> or "script" that depends on the "Some text" as input.
> 
> So for example.
> 
> Random <U>Dogs</U> eat my followers
> turns into
> 
> Random Dogs <sup>Pink</sup> eat my followers
> With "<sup>Pink</sup>" being the output of `scatter 'Dog'`
> 
> Any clues? I was hoping awk would help, but other than pattern
> matching, no such luck. Sed has also left me in the cold so far. Short
> of a bash script that does the search, makes a replacement array, then
> does the search and replace?

This does the trick, but sorry - uses perl :)

perl -n -e 's/<U>([^<]+)<\/U>/"<sup>" . `echo -n $1` . "<\/sup>"/eg; print;'

Direct your input into the command and it'll process line by line.

In the above my external command is simply echo, so the matched text is
return as-is. You can substitute this for whatever.


Jason Nicholls.



More information about the plug mailing list