寻找解决方案,在Lua替换以下命令: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
请为样本输入添加样本输入和您想要的输出到您的问题。 – Cyrus
'[^;] *'匹配0或更多字符,而不是'; - 为什么如果你的输入没有分号就使用它?你想在Lua中获得什么输出? –
如果您需要获得'192.168.34.165',请检查https://ideone.com/s1U60B。 –