Forum Linux.débutant Aide trie avec sort

Posté par  . Licence CC By‑SA.
Étiquettes :
4
5
oct.
2019

Bonjour,

J'ai le fichier toto qui contient:
0.16475E+02,0.58000E+01,0.71643E-02
0.16700E+02,0.58000E+01,0.72830E-02
0.16250E+02,0.60000E+01,0.91514E-02
0.16475E+02,0.60000E+01,0.79116E-02
0.16700E+02,0.60000E+01,0.78501E-02
0.16475E+02,0.74000E+01,0.31863E-01
0.16700E+02,0.74000E+01,0.28469E-01
0.16700E+02,0.26000E+01,0.10060E-01
0.16950E+02,0.26000E+01,0.10460E-01
0.17200E+02,0.26000E+01,0.10782E-01
0.17450E+02,0.26000E+01,0.10960E-01
0.17700E+02,0.26000E+01,0.11068E-01
0.16700E+02,0.28000E+01,0.97771E-02
0.16950E+02,0.28000E+01,0.10137E-01
0.17200E+02,0.28000E+01,0.10304E-01
0.17450E+02,0.28000E+01,0.10219E-01
0.17700E+02,0.28000E+01,0.10164E-01
0.16950E+02,0.38000E+01,0.93556E-02
0.17700E+02,0.42000E+01,0.97942E-02
0.16700E+02,0.44000E+01,0.89748E-02
0.16950E+02,0.44000E+01,0.93447E-02
0.17200E+02,0.44000E+01,0.97008E-02
0.17450E+02,0.44000E+01,0.98781E-02
0.17700E+02,0.44000E+01,0.98557E-02
0.16700E+02,0.46000E+01,0.91781E-02
0.16950E+02,0.46000E+01,0.94142E-02
0.17200E+02,0.46000E+01,0.96254E-02
0.17450E+02,0.46000E+01,0.97590E-02
0.17700E+02,0.46000E+01,0.97697E-02
0.16700E+02,0.48000E+01,0.87545E-02
0.16950E+02,0.48000E+01,0.88285E-02
0.17200E+02,0.48000E+01,0.89413E-02

J'essaie de le trier selon la seconde colonne avec:
sort -g -t ',' -k 2 toto
Mais cela ne fonctionne pas. Une idée ? Il est censé reconnaitre la notation scientifique avec -g c'est bien ça ?

  • # Voir la locale

    Posté par  (site Web personnel) . Évalué à 10.

    Ça marche avec LC_ALL=C sort -g -t ',' -k 2 toto

    Explication : probable que sort utilise la locale courante pour le traitement des nombres, donc recherche une , comme point décimal. Avec le LC_ALL=C tu reviens au . comme point décimal et ça trie correctement.

    0.16700E+02,0.26000E+01,0.10060E-01
    0.16950E+02,0.26000E+01,0.10460E-01
    0.17200E+02,0.26000E+01,0.10782E-01
    0.17450E+02,0.26000E+01,0.10960E-01
    0.17700E+02,0.26000E+01,0.11068E-01
    0.16700E+02,0.28000E+01,0.97771E-02
    0.16950E+02,0.28000E+01,0.10137E-01
    0.17200E+02,0.28000E+01,0.10304E-01
    0.17450E+02,0.28000E+01,0.10219E-01
    0.17700E+02,0.28000E+01,0.10164E-01
    0.16950E+02,0.38000E+01,0.93556E-02
    0.17700E+02,0.42000E+01,0.97942E-02
    0.16700E+02,0.44000E+01,0.89748E-02
    0.16950E+02,0.44000E+01,0.93447E-02
    0.17200E+02,0.44000E+01,0.97008E-02
    0.17450E+02,0.44000E+01,0.98781E-02
    0.17700E+02,0.44000E+01,0.98557E-02
    0.16700E+02,0.46000E+01,0.91781E-02
    0.16950E+02,0.46000E+01,0.94142E-02
    0.17200E+02,0.46000E+01,0.96254E-02
    0.17450E+02,0.46000E+01,0.97590E-02
    0.17700E+02,0.46000E+01,0.97697E-02
    0.16700E+02,0.48000E+01,0.87545E-02
    0.16950E+02,0.48000E+01,0.88285E-02
    0.17200E+02,0.48000E+01,0.89413E-02
    0.16475E+02,0.58000E+01,0.71643E-02
    0.16700E+02,0.58000E+01,0.72830E-02
    0.16250E+02,0.60000E+01,0.91514E-02
    0.16475E+02,0.60000E+01,0.79116E-02
    0.16700E+02,0.60000E+01,0.78501E-02
    0.16475E+02,0.74000E+01,0.31863E-01
    0.16700E+02,0.74000E+01,0.28469E-01
    

    Python 3 - Apprendre à programmer dans l'écosystème Python → https://www.dunod.com/EAN/9782100809141

Suivre le flux des commentaires

Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.