我有两个文件,一个是
这是我的
我想从
这是我的当前bash:
这是我的当前输出:
ips.yaml
。-
dedicatedip: 1.1.1.11
-
dedicatedip: 2.2.2.2
-
dedicatedip: ''
-
dedicatedip: 3.3.3.3
-
dedicatedip: 3.3.3.33
这是我的
result.txt
文件内容:+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| id | hostname | some other field | status | networks | plan |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| 11111111 | some-hostname | some-value | Active | External_Networks=1.1.1.11 | not important |
| 11111111 | some another hostname | | Active | External_Networks=1.1.1.111 | not important |
| 11111111 | some.fqdn.com | | Active | External_Networks=1.1.1.112 | not important |
| 11111111 | fourth.hostname.com | | Active | External_Networks=1.1.1.1 | not important |
| 11111111 | the-other.com | IHaveSomething | Active | External_Networks=2.2.2.2 | not important |
| 11111111 | not.least.com | | Active | External_Networks=2.2.2.25 | not important |
| 11111111 | last.fqdn.com | The Last Value | Active | External_Networks=3.3.3.39 | not important |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
我想从
ips.yaml
中删除每个已存在的IP,并将其从result.txt
中移除,以便获得预期的输出结果。+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| id | hostname | some other field | status | networks | plan |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| 11111111 | some another hostname | | Active | External_Networks=1.1.1.111 | not important |
| 11111111 | some.fqdn.com | | Active | External_Networks=1.1.1.112 | not important |
| 11111111 | fourth.hostname.com | | Active | External_Networks=1.1.1.1 | not important |
| 11111111 | not.least.com | | Active | External_Networks=2.2.2.25 | not important |
| 11111111 | last.fqdn.com | The Last Value | Active | External_Networks=3.3.3.39 | not important |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
这是我的当前bash:
while read -r yaml_ips
do
while read -r result_ips
do
if [ "$yaml_ips" == "$result_ips" ]
then
sed "/$yaml_ips/d" result.txt
fi
done < <(grep -Eo 'External_Networks=[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' result.txt | awk -F '=' '{print $2}')
done < <(awk '/dedicatedip: [0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/ {print $2}' ips.yaml)
这是我的当前输出:
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| id | hostname | some other field | status | networks | plan |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| id | hostname | some other field | status | networks | plan |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
| 11111111 | some-hostname | some-value | Active | External_Networks=1.1.1.11 | not important |
| 11111111 | some another hostname | | Active | External_Networks=1.1.1.111 | not important |
| 11111111 | some.fqdn.com | | Active | External_Networks=1.1.1.112 | not important |
| 11111111 | fourth.hostname.com | | Active | External_Networks=1.1.1.1 | not important |
| 11111111 | last.fqdn.com | The Last Value | Active | External_Networks=3.3.3.39 | not important |
+----------+-----------------------+------------------+--------+-----------------------------+---------------+
$NF
或最后一个字段。此外,所有计划名称都有两个部分“A B”,这就是为什么我添加了一个空格。是的,你是对的。我本可以为所有计划写一个名称,只是为了表明最后一个字段不是“网络”。 - undefined