awk vlookupと印刷

awk vlookupと印刷

カンマ区切りのファイルがあります。

# cat data

smartplayer,2222,off
smartplayer,1111,on
scorer,0000,

$1でsmartplayerを検索し、$3からステータスを取得して、次のように印刷したいと思います。

off-smart-player 2222
on-smart-player 1111
scorer 0000

このコマンドを実行しましたが、次のように印刷されます。

# awk '{ if ($1 == smartplayer ) {print $3"-smart-player", $2}}'  data

-smart-player 
-smart-player 

ベストアンサー1

フィールド区切り文字を指定する必要があります。

awk -F, '$1=="smartplayer"{ print $3"-smart-player", $2; next }
                          { $1=$1; print }' data

おすすめ記事