0

Is there such a thing that finds numbers using regex and can perform simple arithmetic operations to it?

Imagine you have a source/config file storing positions and later changed the code which requires an offset now. How do you normally go about this without doing it manually?

Edit: I knew I should've added this bit with the orignal post. I'd prefer something small and easily acquired from anywhere. I am aware of Cygwin and the wonderful util sets of linux which is why I explicitly put Windows in the title.

Kara
  • 6,115
  • 16
  • 50
  • 57
syaz
  • 2,659
  • 6
  • 36
  • 44

1 Answers1

1

Get yourself a copy of Cygwin and train yourself up on bash, awk, sed, grep and their brethren.

The Windows cmd language has come a long way since the brain-dead days of MSDOS 3.3 but it's still not a wart on the rear end of the UNIX tools. Cygwin gives you all those tools and more.

A way of doing your specific task (if I understand it correctly) is to change:

a b 70         into         offset 60
c d 82                      a b 10
e f 90                      c d 22
                            e f 30

The following command shows how to use awk to acheive that:

$ echo 'a b 70
        c d 82
        e f 90' | awk '
    BEGIN {
        print "offset 60"
    }
    {
        print $1, $2, $3-60
    }'

That's formatted for readability - I would tend to do it all on one line and get my input from a file rather than echoing it, but this is just for demo purposes.

If you want something a little more lightweight (in terms of what you have to install - it's still very powerrful), GnuWin32 can give you individual packagaes. Just install gawk or whatever you need.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Cygwin runs under Windows so I'm not sure I understand your concern. But you can find the utilities compiled for native Windows as well. Updated answer with GnuWin32. – paxdiablo Sep 29 '09 at 02:01
  • Thanks, GnuWin32 looks like what I need. Cygwin is definitely the way to go for personal workspace but if not I'd prefer something lightweight and easy to install/uninstall. – syaz Sep 29 '09 at 02:13
  • I've had troubles before with Cygwin where I haven't installed absolutely *everything*. But honestly, do I need a full-blown Xserver on my desktop? :-) I actually use Cygwin for my work boxes but GnuWin32 where I just need a couple of things. – paxdiablo Sep 29 '09 at 02:17