开发者

Extract IP with sed from command

I've a string which looks like:

BOOT_IMAGE=/boot/vmlinuz-2.6.32-31-generic HTTP_BOOT=192.168.1.133 root=UUID=b4 ro quiet splash

In example "/proc/cmdline"

I would like to extract HTTP_BOOT with sed. My current sed command looks li开发者_运维百科ke that.

HTTP_BOOT=$(sed -r 's/^.*HTTP_BOOT=(.*?).*/\1/' /proc/cmdline)

The var HTTP_BOOT should contain 192.168.1.133. Would be really happy if someone could correct my sed.

Thanks


Try this :

HTTP_BOOT=$(sed 's/.*HTTP_BOOT=\([^ ]*\) .*/\1/' < /proc/cmdline)


You are almost there. Try this sed:

sed -r 's/^.*HTTP_BOOT=([^\ ]*).*$/\1/'


HTTP_BOOT=$(egrep -o 'HTTP_BOOT=[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' /proc/cmdline | cut -d '=' -f 2)

Also does a nice minor sanity check on the IP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜