Linux bashのcsvフィルタ

Linux bashのcsvフィルタ

質問:

5列のCSVファイルがあります(最初の列は文字列で、残りの4列は整数です)。新しいCSVファイルの3番目の列「インポート」に基づいてフィルタリングしたいと思います。最大の列は上部に、最小の列は下部にあります。

次のようなものを使用する必要があるようです。awk -F '","' 'BEGIN {OFS=","} { if (Revenues($5) > ?? print }' Valuation.csv > Ranking.csv

データ:

Company,Nbr employees, Revenues  , Revenues per employee , Valuation 
Facebook,"35,587","55,800,000,000","1,567,988","491,000,000,000"
Uber,"16,000","11,300,000,000","706,250","120,000,000,000"
Snapchat,"3,069","1,180,000,000","384,490","7,200,000,000"
Airbnb,"3,100","2,600,000,000","838,710","38,000,000,000"
LinkedIn,"13,000","26,200,000,000","2,015,385","26,200,000,000"
Coursora,280,"140,000,000","500,000","815,000,000"
Google,"98,771","39,120,000,000","396,068","720,000,000,000"
Stripe,"1,500","450,000,000","300,000","22,500,000,000"
Epic Games,700,"3,000,000,000","4,285,714","15,000,000,000"
Grab,"3,000","2,750,000,000","916,667","10,000,000,000"
Pinterest,800,"1,000,000,000","1,250,000","12,000,000,000"

ベストアンサー1

この試み、

 head -1 Valuation.csv > Ranking.csv && tail -n+2 Valuation.csv | sort -t '"' -nrk4 >> Ranking.csv
  • head ....タイトルをランクファイルにコピー
  • tail .... | sort ...4番目の列は、区切り文字であるヘッダーを除いてソートされます"
  • -n+22行目からファイルを印刷します
  • -nrk4"数値を区切り文字として使用して、4番目の列を逆順に並べ替えます。

出力:

Company,Nbr employees, Revenues  , Revenues per employee , Valuation 
Facebook,"35,587","55,800,000,000","1,567,988","491,000,000,000"
Google,"98,771","39,120,000,000","396,068","720,000,000,000"
LinkedIn,"13,000","26,200,000,000","2,015,385","26,200,000,000"
Uber,"16,000","11,300,000,000","706,250","120,000,000,000"
Grab,"3,000","2,750,000,000","916,667","10,000,000,000"
Airbnb,"3,100","2,600,000,000","838,710","38,000,000,000"
Snapchat,"3,069","1,180,000,000","384,490","7,200,000,000"
Stripe,"1,500","450,000,000","300,000","22,500,000,000"
Epic Games,700,"3,000,000,000","4,285,714","15,000,000,000"
Pinterest,800,"1,000,000,000","1,250,000","12,000,000,000"
Coursora,280,"140,000,000","500,000","815,000,000"

おすすめ記事