这是我文件的结构:
/**** Some Text here ****/
UN 10.147.243.93 51.46 KB 256 34.2%
UN 10.147.243.89 83.05 KB 256 34.6%
DN 10.147.243.88 66.43 KB 256 32.7%
这是我的剧本
file=$1
echo $file
if grep -q DN $File; then
echo "Get the corresponding IP address, It is the treatment that I
want to do next"
fi
但是,这只是diplay的文件名。请问您有个主意吗?
2-我想然后,以提取相应的IP地址。以下是一些详细信息:
if grep -q DN $File; then
echo "Get the corresponding IP address Guest, It is the treatment
that I want to do next"
variable=This address
fi
非常感谢您的帮助。
最好的祝福。
正如指出的那样,你应该纠正$File
错字。
根据你与输出做什么,你可能不需要if
在所有的测试。你说你想存储在一个变量的IP地址:
file=$1
echo $file
ip=$(grep -e DN $1 | awk '{ print $2; }')
echo $ip
这可以简化它的价值了很多进一步的,但它符合你有什么了。
请注意,这只会匹配第一个文件中对应于“DN”的IP的实例; 该行为是由您使用的暗示-q
来选择grep
其立即退出的第一场比赛。
如果你想要做的事与每次出现时,你会做不同的事情。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句