シェル: 複数列ファイルの処理

シェル: 複数列ファイルの処理

次の形式の列ファイルはmacOSを使用しています。

 ./tmp/7000_CNE_lig752_cl_0.5| -10.1000| 58
./tmp/7000_CNE_lig1029_cl_0.5| -8.0200| 40
./tmp/7000_CNE_lig183_cl_0.5| -8.0400| 32
./tmp/7000_CNE_lig247_cl_0.5| -8.3000| 28
./tmp/7000_CNE_lig331_cl_0.5| -8.9400| 31
./tmp/7000_CNE_lig578_cl_0.5| -8.2400| 76
./tmp/7000_CNE_lig587_cl_0.5| -8.5800| 35
./tmp/7000_CNE_lig659_cl_0.5| -8.0600| 31
./tmp/7000_CNE_lig679_cl_0.5| -8.7500| 36
./tmp/7000_CNE_lig767_cl_0.5| -8.9600| 86
./tmp/7000_CNE_lig830_cl_0.5| -8.2700| 32
./tmp/7000_CNE_lig841_cl_0.5| -8.1600| 32
./tmp/7000_CNE_lig842_cl_0.5| -8.5700| 33
./tmp/7000_CNE_lig900_cl_0.5| -8.1400| 61
./tmp/7000_CNE_lig931_cl_0.5| -8.9400| 40
./tmp/7000_CNE_lig933_cl_0.5| -8.6200| 101
./tmp/7000_CNE_lig987_cl_0.5| -8.6200| 55
./tmp/7000_CNE_lig996_cl_0.5| -8.2300| 31
./tmp/7000_CNE_lig998_cl_0.5| -8.6800| 48
./tmp/7000_CNE_lig999_cl_0.5| -8.0000| 29
./tmp/7000_CNE_lig1002_cl_0.5| -7.0900| 32
./tmp/7000_CNE_lig1009_cl_0.5| -7.4600| 22
./tmp/7000_CNE_lig1023_cl_0.5| -7.8700| 25
./tmp/7000_CNE_lig1032_cl_0.5| -7.1200| 20
./tmp/7000_CNE_lig1033_cl_0.5| -7.4400| 26
./tmp/7000_CNE_lig118_cl_0.5| -7.4400| 11
./tmp/7000_CNE_lig179_cl_0.5| -7.8000| 26
./tmp/7000_CNE_lig180_cl_0.5| -7.3800| 38
./tmp/7000_CNE_lig24_cl_0.5| -7.3600| 32
./tmp/7000_CNE_lig25_cl_0.5| -7.0600| 26

2番目の列に基づいて値を最も低いものから最も高いものにソートする1​​行のSORTコマンドが必要です。 sort コマンドを使用して試した内容は次のとおりです。

sort -t'|' -nk2 7000_CNE_TOP.csv
7000_CNE_lig752_cl_0.5| -10.1000| 58
7000_CNE_lig1029_cl_0.5| -8.0200| 40
7000_CNE_lig183_cl_0.5| -8.0400| 32
7000_CNE_lig247_cl_0.5| -8.3000| 28
7000_CNE_lig331_cl_0.5| -8.9400| 31
7000_CNE_lig578_cl_0.5| -8.2400| 76
7000_CNE_lig587_cl_0.5| -8.5800| 35
7000_CNE_lig659_cl_0.5| -8.0600| 31
7000_CNE_lig679_cl_0.5| -8.7500| 36
7000_CNE_lig767_cl_0.5| -8.9600| 86
7000_CNE_lig830_cl_0.5| -8.2700| 32
7000_CNE_lig841_cl_0.5| -8.1600| 32
7000_CNE_lig842_cl_0.5| -8.5700| 33
7000_CNE_lig900_cl_0.5| -8.1400| 61
7000_CNE_lig931_cl_0.5| -8.9400| 40
7000_CNE_lig933_cl_0.5| -8.6200| 101
7000_CNE_lig987_cl_0.5| -8.6200| 55
7000_CNE_lig996_cl_0.5| -8.2300| 31
7000_CNE_lig998_cl_0.5| -8.6800| 48
7000_CNE_lig999_cl_0.5| -8.0000| 29
7000_CNE_lig1002_cl_0.5| -7.0900| 32
7000_CNE_lig1009_cl_0.5| -7.4600| 22
7000_CNE_lig1023_cl_0.5| -7.8700| 25
7000_CNE_lig1032_cl_0.5| -7.1200| 20
7000_CNE_lig1033_cl_0.5| -7.4400| 26
7000_CNE_lig118_cl_0.5| -7.4400| 11
7000_CNE_lig179_cl_0.5| -7.8000| 26
7000_CNE_lig180_cl_0.5| -7.3800| 38
7000_CNE_lig24_cl_0.5| -7.3600| 32

または、同じ結果を提供する-nk 2,2を使用してください。

sort -t'|' -nk2,2 7000_CNE_TOP.csv
7000_CNE_lig752_cl_0.5| -10.1000| 58
7000_CNE_lig1029_cl_0.5| -8.0200| 40
7000_CNE_lig183_cl_0.5| -8.0400| 32
7000_CNE_lig247_cl_0.5| -8.3000| 28
7000_CNE_lig331_cl_0.5| -8.9400| 31
7000_CNE_lig578_cl_0.5| -8.2400| 76
7000_CNE_lig587_cl_0.5| -8.5800| 35
7000_CNE_lig659_cl_0.5| -8.0600| 31
7000_CNE_lig679_cl_0.5| -8.7500| 36
7000_CNE_lig767_cl_0.5| -8.9600| 86
7000_CNE_lig830_cl_0.5| -8.2700| 32
7000_CNE_lig841_cl_0.5| -8.1600| 32
7000_CNE_lig842_cl_0.5| -8.5700| 33
7000_CNE_lig900_cl_0.5| -8.1400| 61
7000_CNE_lig931_cl_0.5| -8.9400| 40
7000_CNE_lig933_cl_0.5| -8.6200| 101
7000_CNE_lig987_cl_0.5| -8.6200| 55
7000_CNE_lig996_cl_0.5| -8.2300| 31
7000_CNE_lig998_cl_0.5| -8.6800| 48
7000_CNE_lig999_cl_0.5| -8.0000| 29
7000_CNE_lig1002_cl_0.5| -7.0900| 32
7000_CNE_lig1009_cl_0.5| -7.4600| 22
7000_CNE_lig1023_cl_0.5| -7.8700| 25
7000_CNE_lig1032_cl_0.5| -7.1200| 20
7000_CNE_lig1033_cl_0.5| -7.4400| 26
7000_CNE_lig118_cl_0.5| -7.4400| 11
7000_CNE_lig179_cl_0.5| -7.8000| 26
7000_CNE_lig180_cl_0.5| -7.3800| 38

ベストアンサー1

sed浮動小数点数をソートするには、ロケールをオフにして1を使用します。

sed 's=^\./tmp/\([^|]*\)\.txt|=\1|=' 1 | LC_ALL=C sort -t'|' -k2,2n

sed式は./tmp/各行の先頭から削除しますが、.txt最初の行の前の内容も削除します|。これがキャッチが非パイプラインと一致する理由です。

-k2,2私は2番目の列に基づいて並べ替えました。ただ。 2番目の列の値が同じ場合は、-k2次の列に基づいて並べ替えられます(この場合は何が必要かわかりません)。

おすすめ記事