简体   繁体   中英

Windows utility to find numbers and do operations?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM