Stack Overflow Asked by user9938830 on January 18, 2021
This is an example of my code with Lua
local p = io.popen('nslookup myip.opendns.com resolver1.opendns.com', 'r');
local output = p:read('a+');
p:close();
print (output)
Whose output is something like the following:
Server: resolver1.opendns.com
Address: 208.67.222.222
Name: myip.opendns.com
Address: 85.185.195.150
But I want only Address: 85.185.195.150 to be printed
How can I do this?
A regular expression and tail last line for the desired output.
local p = io.popen('nslookup hostname resolver | grep -o -E "^Address:.([0-9.]{2,4}){4}$" | tail -n1', 'r');
But you dont need a regular expression. Try...
local p = io.popen('nslookup hostname resolver | tail -n2', 'r');
Answered by koyaanisqatsi on January 18, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP