On Sun, 18 Nov 2001, Manfred Tremmel wrote:
meine_ip=`/sbin/ifconfig ippp0 | grep 'inet addr:' | cut -f2 -d":" | awk '{ print $1 }'`
"The neverending Thread" oder was??? ==== dynip.sh ==== ### USAGE: dynip.sh [INTERFACE] IF="${1:-ppp0}"; /sbin/ifconfig $IF | sed -n 's/.*addr:\([0-9\.]*\).*/\1/p'; ==== Benchmarks zum Thema gibt's (von mir) im Archiv... Und auf Anfrage nochmal das bench-script... -dnh PS: Obige Variante hatte ich noch nicht, sollte aber aequivalent sein zu: grep ... | awk ... | cut ... (='tj2')... Ach was solls (leicht umformatiert und die aufgerufenen "Prozesse" als Kommentar eingefuegt)... $ ~/bin/dynip_testing.sh 2>&1 | grep 'real\|:' tj1: real 0m4.632s ## grep | awk | cut | perl tj2: real 0m3.287s ## grep | awk | cut dh4: real 0m1.805s ## echo `grep | sed` dh2: real 0m1.646s ## grep | sed dh1: real 0m1.324s ## sed (s.o.) dh3: real 0m1.381s ## echo `sed` sd1: real 0m2.055s ## perl ww1: real 0m2.261s ## grep | cut | cut mh1: real 0m4.322s ## grep | awk | awk mt1: real 0m3.267s ## grep | cut | awk (s.o.) dh5: real 0m0.957s ## bash-only dh1() ist obige Variante die mit einem sed auskommt. Und die ist _reproduzierbar_ die schnellste, die mir bisher ueber den Weg gelaufen ist. Ach, dascha interessant...: 'grep | awk | cut' ('tj2') ist langsamer als 'grep | cut | awk' ('mt1', s.o.)... :) Weitere Varianten sind gern gesehen *scnr*... ich tippe mal, nur bash-intern ist schneller.... die ich dann mal eben als 'dh5' selbst geschrieben habe: dh5() { while read l; do m="${l%%*addr:[0-9.]*}"; if test "x$m" = "x"; then a="${l//addr:/}"; a="${a// */}"; echo "$a"; fi; done; } -d'take 2'h -- "What's the word for a meal that's too late for breakfast or lunch, but too early for dinner, and takes the place of all three?" "Pizza." -- Joe Thompson and Christian Bauernfeind