De acordo com as Leis 12.965/2014 e 13.709/2018, que regulam o uso da Internet e o tratamento de dados pessoais no Brasil, ao me inscrever na newsletter do portal DICAS-L, autorizo o envio de notificações por e-mail ou outros meios e declaro estar ciente e concordar com seus Termos de Uso e Política de Privacidade.


O comando sort (1)

Colaboração: Rubens Queiroz de Almeida

Data de Publicação: 23 de Junho de 1997

O comando sort, também oferece inúmeras facilidades interessantes. Tomemos o arquivo abaixo como exemplo:

arq1

  1:2:3:4:5:6
  1:1:3:4:5:6
  1:4:3:4:5:6
  1:2:3:4:5:6
  1:0:3:4:5:6
  1:2:3:4:5:6
  1:7:3:4:5:6
  1:2:3:4:5:6
  1:0:3:4:5:6
  1:9:3:4:5:6

O comando abaixo

  % sort -t: +1 -n arq1

irá gerar a seguinte saída

    |
    v
  1:0:3:4:5:6
  1:0:3:4:5:6
  1:1:3:4:5:6
  1:2:3:4:5:6
  1:2:3:4:5:6
  1:2:3:4:5:6
  1:2:3:4:5:6
  1:4:3:4:5:6
  1:7:3:4:5:6

Observar que o segundo campo, indicado pela seta, está ordenado numericamente em ordem crescente. Os campos deste arquivo são separados por ":". O tipo de separador é indicado pela flag "-t:". Em seguida à flag "-t" poderíamos indicar qualquer tipo de separador. O campo a ser ordenado é indicado pela flag "+1". Para o comando sort a contagem dos campos inicia-se por 0, desta forma, o valor "+1" irá indicar na realidade o segundo campo do arquivo. A ordenação também pode ser feita numericamente, do maior para o menor valor:

  % sort -t: +1 -nr arq1
  
    |
    v
  1:9:3:4:5:6
  1:7:3:4:5:6
  1:4:3:4:5:6
  1:2:3:4:5:6
  1:2:3:4:5:6
  1:2:3:4:5:6
  1:2:3:4:5:6
  1:1:3:4:5:6
  1:0:3:4:5:6
  1:0:3:4:5:6

Dica Humorística :-)

Troutman's Laws of Computer Programming

  1. Any running program is obsolete.
  2. Any planned program costs more and takes longer.
  3. Any useful program will have to be changed.
  4. Any useless program will have to be documented.
  5. The size of a program expands to fill all available memory.
  6. The value of a program is inversely proportional to the weight of output
  7. The complexity of a program grows until it exceeds the capability of the maintainers.
  8. Information necessitating a change in design is always conveyed to the implementors after the code is written. Corollary: Given a simple choice between one obviously right way and one obviously wrong way, it is often wiser to choose the wrong way, so as to expedite subsequent revision.
  9. The more innocuous a modification appears, the more code it will require rewriting.
  10. If a test installation functions perfectly, all subsequent systems will malfunction.
  11. Not until a program has been in production for at least six months will the most harmful error be discovered.
  12. Interchangeable modules won't.
  13. Any system that relies on computer reliability is unreliable.
  14. Any system that relies on human reliability is unreliable.
  15. Investment in reliability increases until it exceeds the probable cost of errors, or until someone insists on getting some useful work done.
  16. Adding manpower to a late software project makes it later.
  17. There's always one more bug.

Adicionar comentário

* Campos obrigatórios
5000
Powered by Commentics

Comentários

Nenhum comentário ainda. Seja o primeiro!


Veja a relação completa dos artigos de Rubens Queiroz de Almeida