algebaric operations on a RegEx?

Chris F.A. Johnson cfaj-uVmiyxGBW52XDw4h08c5KA at public.gmane.org
Sun Apr 5 03:08:10 UTC 2009


On Sat, 4 Apr 2009, matt.price-H217xnMUJC0sA/PxXw9srA at public.gmane.org wrote:

> I want to quickly play with some numeric values in an xml file (xbmc's 
> Fontxml files, of which there are often a number in any given skin).  what I 
> need to do is find lines like:
> <size>13</size> and augment or decrement the values by a set number.  so i'd 
> like a command addsize, like this:
>
> addsize 4 font.xml
>
> that would change  the above to <size>17</size>
>
> someone out there actually understand how to use perl, and willing to show me 
> how to do this?  thanks much,

     It's simpler with awk than perl:

awk -v add=$1 '/<size>[0-9]+<\/size>/ {
    n = $0
    gsub( /[^0-9]/,"",n)
    gsub( /[0-9]+/, n + add) }
    { print }
' "$2" > tempfile$$ && mv tempfile$$ "$2"

-- 
    Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, webmaster         <http://woodbine-gerrard.com>
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list