Jos*_*izo 1 linux bash awk sed centos7
我有这些输出的变量:
$nw_monitor
Host has 'em3, em2, em1, em4' network devices
em3 does not have any ip rules, skipping health checks
Checking health of 'em2'
Checking health of 'em1'
em4 does not have any ip rules, skipping health checks
Host has 2 healthy network links
Run Code Online (Sandbox Code Playgroud)
还有第二个变量。
$link
Speed : 10 Gb/s
Link status : yes
Speed : 10 Gb/s
Link status : yes
Run Code Online (Sandbox Code Playgroud)
从第二个变量中,它给出了 $nw_monitor、em2 和 em1 中提到的每个接口的速度和链接状态。
所以我想将它们混合起来,看起来像这样:
Host has 'em3, em2, em1, em4' network devices
em3 does not have any ip rules, skipping health checks
Checking health of 'em2'
Speed : 10 Gb/s
Link status : yes
Checking health of 'em1'
Speed : 10 Gb/s
Link status : yes
em4 does not have any ip rules, skipping health checks
Host has 2 healthy network links
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这个:
sed /^Checking/R<(echo "$link") <(echo "$nw_monitor")
Run Code Online (Sandbox Code Playgroud)
但是,我得到了他的输出:
Host has 'em3, em2, em1, em4' network devices
em3 does not have any ip rules, skipping health checks
Checking health of 'em2'
Speed : 10 Gb/s
Checking health of 'em1'
Link detected : yes
em4 does not have any ip rules, skipping health checks
Host has 2 healthy network links
Run Code Online (Sandbox Code Playgroud)
为什么它们在字符串中?我认为这在简单文件中会更容易。
$: echo "$nw_monitor">a
$: echo "$link">b
$: while read a
> do echo "$a"
> case "$a" in Checking*) for c in 1 2; do read b <&3; echo " $b"; done;; esac
> done <a 3<b
Host has 'em3, em2, em1, em4' network devices
em3 does not have any ip rules, skipping health checks
Checking health of 'em2'
Speed : 10 Gb/s
Link status : yes
Checking health of 'em1'
Speed : 10 Gb/s
Link status : yes
em4 does not have any ip rules, skipping health checks
Host has 2 healthy network links
Run Code Online (Sandbox Code Playgroud)
但如果你只需要它们在字符串中......
$: while read a
> do echo "$a"
> case "$a" in Checking*) for c in 1 2; do read b <&3; echo " $b"; done;; esac
> done < <(echo "$nw_monitor") 3< <(echo "$link")
Host has 'em3, em2, em1, em4' network devices
em3 does not have any ip rules, skipping health checks
Checking health of 'em2'
Speed : 10 Gb/s
Link status : yes
Checking health of 'em1'
Speed : 10 Gb/s
Link status : yes
em4 does not have any ip rules, skipping health checks
Host has 2 healthy network links
Run Code Online (Sandbox Code Playgroud)