Bashで複数の変数を使用する方法

Bashで複数の変数を使用する方法

user.txt90人を超えるユーザーがいる次のコンテンツを含むファイル()があります。

  • サンプルファイルの内容
    user: Ronaldo
    id:7
    endpoint:manutd.com
    user: Messi
    id:30
    endpoint:psg.com
    user: Neymar
    id:10
    endpoint:psg.com
    
  • 希望の出力:
    Ronaldo is in manutd.com and wears no 7
    Messi is in psg.com and wears no 30
    .
    .
    
    すべてのユーザーなど

Bashスクリプトを使ってどのように印刷できますか?

ベストアンサー1

あなたはこれを使うことができますawk

awk -F: '/user/ {name=$2 " is in "; next} /id/{id="no "$2;next} /endpoint/ {team=$2 " and wears "} {print name, team, id }' $inputfile

出力

 Ronaldo is in  manutd.com and wears  no 7
 Messi is in  psg.com and wears  no 30
 Neymar is in  psg.com and wears  no 10

予想される大文字の出力が間違っていると仮定していますが、そうでない場合は指摘してください。

おすすめ記事