Fli
04-17-2014, 09:21 AM
Recently i wanted to get an IP of a domain from within linux command line,
the command is:
dig +short internetlifeforum.com
but this command returned several IPs one per line. SO icwanted to have only one line in that command output. So i asked Google:
- linux command use only first line output
- how to use only n line out of command result
i found this:
dig +short internetlifeforum.com | head -n 1
it will return just first line. If one wants to give this IP into variable, it can be done:
domain=internetlifeforum.com
variablename=$(dig +short $domain | head -n 1)
the command is:
dig +short internetlifeforum.com
but this command returned several IPs one per line. SO icwanted to have only one line in that command output. So i asked Google:
- linux command use only first line output
- how to use only n line out of command result
i found this:
dig +short internetlifeforum.com | head -n 1
it will return just first line. If one wants to give this IP into variable, it can be done:
domain=internetlifeforum.com
variablename=$(dig +short $domain | head -n 1)