序号递增(半自动)

黄杰, 2015-06-29
root[a]linuxsand.info

ABB 机器人的配置文件是纯文本的,包括信号配置文件 EIO.CFG。有时,我需要批量建立一些新信号,名字递增,类似 vdo1, vdo2...

-Name "vdi1" -SignalType "DI" -Unit "MyVirtual" -UnitMap "0" -Access "Default"

数量一多,就嫌麻烦了。本打算写个小工具,做了一半嫌麻烦,又放弃了。

还是借助现有工具吧,例如 EXCEL / WPS。宗旨就是为了偷懒嘛。


在语句的数字左右添加英文逗号。表格软件可能会把引号吃掉——随便插个反斜杠,这个可以批量替换:

-Name \"vdi,1,\" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \",0,\" -Access \"Default\"

然后,另存为 CSV 文件。用 WPS 打开,拖选自动累加,复制出来。

贴回编辑器。

-Name \"vdi 1   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   0   \" -Access \"Default\"
-Name \"vdi 2   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   1   \" -Access \"Default\"
-Name \"vdi 3   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   2   \" -Access \"Default\"
-Name \"vdi 4   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   3   \" -Access \"Default\"
-Name \"vdi 5   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   4   \" -Access \"Default\"
-Name \"vdi 6   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   5   \" -Access \"Default\"
-Name \"vdi 7   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   6   \" -Access \"Default\"
-Name \"vdi 8   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   7   \" -Access \"Default\"
-Name \"vdi 9   \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   8   \" -Access \"Default\"
-Name \"vdi 10  \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   9   \" -Access \"Default\"
-Name \"vdi 11  \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   10  \" -Access \"Default\"
-Name \"vdi 12  \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   11  \" -Access \"Default\"
-Name \"vdi 13  \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   12  \" -Access \"Default\"
-Name \"vdi 14  \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   13  \" -Access \"Default\"
-Name \"vdi 15  \" -SignalType \"DI\" -Unit \"MyVirtual\" -UnitMap \"   14  \" -Access \"Default\"

批量替换掉 Tab 和反斜杠。

-Name "vdi1" -SignalType "DI" -Unit "MyVirtual" -UnitMap "0" -Access "Default"
-Name "vdi2" -SignalType "DI" -Unit "MyVirtual" -UnitMap "1" -Access "Default"
-Name "vdi3" -SignalType "DI" -Unit "MyVirtual" -UnitMap "2" -Access "Default"
-Name "vdi4" -SignalType "DI" -Unit "MyVirtual" -UnitMap "3" -Access "Default"
-Name "vdi5" -SignalType "DI" -Unit "MyVirtual" -UnitMap "4" -Access "Default"
-Name "vdi6" -SignalType "DI" -Unit "MyVirtual" -UnitMap "5" -Access "Default"
-Name "vdi7" -SignalType "DI" -Unit "MyVirtual" -UnitMap "6" -Access "Default"
-Name "vdi8" -SignalType "DI" -Unit "MyVirtual" -UnitMap "7" -Access "Default"
-Name "vdi9" -SignalType "DI" -Unit "MyVirtual" -UnitMap "8" -Access "Default"
-Name "vdi10" -SignalType "DI" -Unit "MyVirtual" -UnitMap "9" -Access "Default"
-Name "vdi11" -SignalType "DI" -Unit "MyVirtual" -UnitMap "10" -Access "Default"
-Name "vdi12" -SignalType "DI" -Unit "MyVirtual" -UnitMap "11" -Access "Default"
-Name "vdi13" -SignalType "DI" -Unit "MyVirtual" -UnitMap "12" -Access "Default"
-Name "vdi14" -SignalType "DI" -Unit "MyVirtual" -UnitMap "13" -Access "Default"
-Name "vdi15" -SignalType "DI" -Unit "MyVirtual" -UnitMap "14" -Access "Default"

半自动完成。不知道有没有更好的半自动、甚至全自动办法。

(Oh,这似乎是一个不存在的需求。)


扩展阅读:我之前有个命令行的办法,可以解决一些简单 index 问题。http://www.linuxsand.info/notes/random/join-text-with-line-numbers.txt