简体   繁体   English

Windows实用程序查找数字并执行操作?

[英]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. 我知道Cygwin和出色的linux util集,这就是为什么我明确将Windows放在标题中的原因。

Get yourself a copy of Cygwin and train yourself up on bash , awk , sed , grep and their brethren. 为自己获取Cygwin的副本,并接受bashawksedgrep及其兄弟的培训。

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. 自从MSDOS 3.3令人生厌的日子以来,Windows cmd语言已经走了很长一段路,但是它仍然不是UNIX工具后端的疣。 Cygwin gives you all those tools and more. Cygwin为您提供了所有这些工具以及更多工具。

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: 以下命令显示了如何使用awk实现该功能:

$ 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. 如果您想要更轻巧的东西(就必须安装的东西而言-它仍然非常强大), GnuWin32可以给您单独的packagaes。 Just install gawk or whatever you need. 只需安装gawk或任何您需要的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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