Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
How to sort text file based on number after first letter

I have a text file in linux that looks like this:

H-988   -0.5418829321861267 no
H-989   -0.5033702254295349 yes
H-990   -1.1516857147216797 hi
H-99    -0.5005123019218445 hello

I want to sort this file based on the number coming after the hyphen. So the order should be:

H-99    -0.5005123019218445 hello
H-988   -0.5418829321861267 no
H-989   -0.5033702254295349 yes
H-990   -1.1516857147216797 hi

I tried the grep sort command but it did not work. For example it puts 95 after 949 instead of before same goes for 99 and 990 as the example provided

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You should sort as numerically,

sort --numeric-sort --field-separator "-" --key 2 some.txt

or a shorter version

sort -n -t "-" -k 2 some.txt
over 4 years ago · Santiago Trujillo Relatório

0

If the first field always has only two characters before the number, you can skip them:

sort -k1.3,1n ip.txt

-k1.3 tells sort to start considering the field (which is 1 here) only from the third character

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda