機略戦記

Maneuver warfare

AWKで現在読み込んでいる行の次の行を表示したい

結論

cat ~/.ssh/config | awk '/xxx-xxx-01/ { print ; getline; print }'

説明

こういうファイルで、Hostに対応するHostNameを取り出したい

$ cat ~/.ssh/config
Host xxx-xxx-01
  HostName xxx.xxx.xxx.xxx
Host xxx-xxx-02
  HostName xxx.xxx.xxx.xxx
Host xxx-xxx-03
  HostName xxx.xxx.xxx.xxx

できた

cat ~/.ssh/config | awk '/xxx-xxx-01/ { print ; getline; print }'
Host xxx-xxx-01
  HostName xxx.xxx.xxx.xxx