user.txt
90人を超えるユーザーがいる次のコンテンツを含むファイル()があります。
- サンプルファイルの内容
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
予想される大文字の出力が間違っていると仮定していますが、そうでない場合は指摘してください。