ファイルからいくつかのデータを読み取り、必要な 2 つの列だけに grep を使用して、出力を変数にリダイレクトしました。
私のスクリプトは次のようになります。
#!/bin/bash
cat hosts.cfg | grep 'address\|host_name' | sed -e 's/\<address\>//g' | while read line; do
echo $line | sed 's/host_name//g' | sed -r 's/\s+//g' ;
done
出力は次のようになります。
Host1
xx.xx.xx.xx
Host2
xx.xx.xx.xx
問題は、hosts と ips をファイルではなく配列に保存する必要があることです!
出力は次のようになります。
Host1(tab)xx.xx.xx.xx
Host2(tab)xx.xx.xx.xx