[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: awk or sed?



Tim:

awk works well if you know where in the output the address is
located (e.g., the fourth word).  sed is better if you need to find
the address somewhere on the line.  Looking at the ifconfig
output, I think sed is better suited:

ifconfig | sed -n '/^eth0/,/^$/s/ *inet addr:\([^ ]*\).*/\1/p'

This basically says:  starting at the "eth0" line, look for a line
with some number of spaces, then the words "inet addr:".  Extract
some number of non-space characters (the address), and replace the
whole line with those characters.  Then, print it.  Stop processing
when you see a blank line (this prevents sed from printing the
address from other interfaces, like ppp0 or lo).

Hope it helps,

Marc

----------
Marc Mongeon <mongeon@bankoe.com>
Unix Specialist
Ban-Koe Systems
9100 W Bloomington Fwy
Bloomington, MN 55431-2200
(612)888-0123, x417 | FAX: (612)888-3344
----------
"It's such a fine line between clever and stupid."
   -- David St. Hubbins and Nigel Tufnel of "Spinal Tap"


>>> Tim Thomson <tim@tui.dhs.org> 09/22/99 07:56PM >>>
Hi,

I want to write a script, that gets the local ip address, and does a
reverse ns lookup, then sets the hostname to the dns response.

I can use grep to get the line I want from ifconfig and nslookup. But how
do I get the numbers and name out of the output? Was it awk or sed, or am
I going along the wrong track?

Thanks,

Tim.

-- 
Tim Thomson               tim@tui.dhs.org 


-- 
Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null



Reply to: