【发布时间】:2019-04-15 15:50:43
【问题描述】:
我正在尝试查看是否可以在几行中实现查找/替换并增加一个整数值。为了解释,我有以下文字:
&sr=1240000000000&type=game&scoreA=x&scoreB=y&
&sr=1150000000000&type=game&scoreB=x&scoreB=y&
&sr=1270000000000&type=game&scoreC=x&scoreB=y&
&sr=1010000000000&type=game&scoreD=x&scoreB=y&
我只想替换 sr= 之后的数字直到... & 所以例如以粗体显示:
&sr=1240000000000&type=game&scoreA=x&scoreB=y&
每找到一个后续数字,所有数字将被替换并增加10000...
理想情况下,当我使用如下脚本时(取 2 个参数,第一个是要替换的值和输入文件):
./script.sh 1500000000000 文件.txt
它应该全部替换为:
&sr=1500000010000&type=game&scoreA=x&scoreB=y&
&sr=1500000020000&type=game&scoreB=x&scoreB=y&
&sr=1500000030000&type=game&scoreC=x&scoreB=y&
&sr=1500000040000&type=game&scoreD=x&scoreB=y&
我编写了一个 python 脚本来实现这一点,但想知道是否有人可以建议我在 1-3 衬里脚本中执行此操作,也许使用 AWK/SED。我的 python 脚本有点长。
【问题讨论】:
-
你能向我们展示你到目前为止的工作吗?