尋找解決方案,在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。 –