【发布时间】:2017-06-18 20:32:40
【问题描述】:
寻找在 Lua 中替换以下命令的解决方案:
grep "dhcp-range" /tmp/etc/dnsmasq.conf | awk -F "\"*,\"*" '{print $2}'
试过
for line in file:lines() do
if line:match("([^;]*),([^;]*),([^;]*),([^;]*),([^;]*)") then
print(line[2])
end
end
它不起作用。
/tmp/etc/dnsmasq.conf 看起来像这样
dhcp-leasefile=/tmp/dhcp.leases
resolv-file=/tmp/resolv.conf.auto
addn-hosts=/tmp/hosts
conf-dir=/tmp/dnsmasq.d
stop-dns-rebind
rebind-localhost-ok
dhcp-broadcast=tag:needs-broadcast
dhcp-range=lan,192.168.34.165,192.168.34.179,255.255.255.0,12h
no-dhcp-interface=eth0
【问题讨论】:
-
请在您的问题中添加示例输入和该示例输入所需的输出。
-
[^;]*匹配除;之外的 0 个或多个字符 - 如果您的输入没有分号,为什么还要使用它?你想在 Lua 中得到什么输出? -
如需获取
192.168.34.165,请查看ideone.com/s1U60B。 -
我想获取以“dhcp-range”开头的行并打印第二个和第三个值。分别是 192.168.34.165 和 192.168.34.179。
-
也许ideone.com/tFzZkZ 可以吗?