Macbookシステムアナライザフォーマット済み

Macbookシステムアナライザフォーマット済み

system_profilerMacbookターミナルコマンドで生成された出力をフォーマットし、行値を同じアプリケーションの下の列に置き換えたいと思います。

以下はファイルの一部です。

Firefoxブラウザ:

  Version: 32.0.3
  Obtained from: Identified Developer
  Last Modified: 28/09/2014 18:23
  Kind: Intel
  64-Bit (Intel): Yes
  Signed by: Developer ID Application: Mozilla Corporation, Developer ID Certification
  Location: /Applications/Firefox.app
  Get Info String: Firefox 32.0.3

Calendar:

  Version: 7.0
  Obtained from: Apple
  Last Modified: 18/03/2014 06:58
  Kind: Intel
  64-Bit (Intel): Yes
  Location: /Applications/Calendar.app

...そして、出力が次のようになります。

1

メモ:

  1. すべての申請書にすべてのフィールドが記入されるわけではありません。
  2. これらのメッセージは最大8つあります(Firefoxアプリケーションの下の完全なセットを参照)。
  3. 各アプリケーション情報グループ間の先行パディングスペースと改行文字

ベストアンサー1

awk -F: ' # set fields separator to :
$1!="" && $2==""{i++;NAME[i]=$1} # if 1st field without second it is app.name
$2!=""{HEAD[$1]=1;DATA[NAME[i],$1]=$2 $3} # put variables name into array
#+ put variables into 2-dimention array app.name,var.name  
END{
printf("%s:","Application"); # first column in header
for (n in HEAD) printf("%s:",n); # print all var.name as header separated by :
print ""; # finish line by newline
for(i in NAME){ # for each app.name
  printf("%s:",NAME[i]); # print app.name
  for (n in HEAD) printf("%s:", DATA[NAME[i],n]); # print each variables corresponding to app.name
  print ""; # finish line by newline
  }
}' data.file | sed -E 's/:\s*/:/g' | column -s: -tn

sed 次のスペースをすべて削除してください。:

columnテキスト列の書式設定

おすすめ記事