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
- Any running program is obsolete.
- Any planned program costs more and takes longer.
- Any useful program will have to be changed.
- Any useless program will have to be documented.
- The size of a program expands to fill all available memory.
- The value of a program is inversely proportional to the weight of output
- The complexity of a program grows until it exceeds the capability of the maintainers.
- 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.
- The more innocuous a modification appears, the more code it will require rewriting.
- If a test installation functions perfectly, all subsequent systems will malfunction.
- Not until a program has been in production for at least six months will the most harmful error be discovered.
- Interchangeable modules won't.
- Any system that relies on computer reliability is unreliable.
- Any system that relies on human reliability is unreliable.
- Investment in reliability increases until it exceeds the probable cost of errors, or until someone insists on getting some useful work done.
- Adding manpower to a late software project makes it later.
- There's always one more bug.