该脚本从文本文件中读取行。一条线看起来像这样。从Bash中的字符串中提取字符串
227 A S comment=comment string dst-address=9.9.9.9/29 gateway=192.168.199.2 gateway-status=192.168.199.2 reachable via LACP1=1 scope=30 target-scope=10
这是赋值的变量$路径
那么我就需要再分配9.9.9.9/29
为变量$subnet
。我不能使用awk
,因为dst-address的列位置在行中会有所不同。
回顾一下,我需要搜索“dst-address=
”的每一行,然后将'='后面的字符串赋值给变量$ subnet。
我的理想解决方案是
while read routes ; do
subnet=< code I need >
done < /tmp/routingTable.txt
'的grep -OP“DST-地址= \ K [ ^] *''? – 123
非常有用的命令,我会有其他用途。谢谢! –