shell-script-pt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [shell-script] Sort em conteudo da linha


From: Thobias Salazar Trevisan
Subject: Re: [shell-script] Sort em conteudo da linha
Date: Wed, 16 Jul 2003 15:13:45 -0300 (BRT)

ae frederico,

On 16 Jul 2003, Frederico BOHNE Espinosa wrote:

>       O comando sort ordena o conteudo de um arquivo linha a linha, e para
> ordenar o conteudo de uma linha?
>
>       Por exemplo:
>
>       5 4 3 2 1, depois do sort da linha --> 1 2 3 4 5
>
>       Existe comando? Como fazer?

não me lembro de um jeito "elegante" para fazer isso. o negócio e
dar uma xunxada.

$ cat teste.sh
#!/bin/bash

for i in `cat lixo | sed 's/$/ ø/'`;do
if [ $i = ø ];then
        echo "$Linha" | sort | sed ':a;$!N;s/\n/ /;ta'
        Linha=""
else
        [ "$Linha" ] && Linha="$Linha
$i" || Linha="$i"
fi
done

$ cat lixo
2 1 1   3
6 8     4
5 4 3 2 1

$ ./teste.sh
1 1 2 3
4 6 8
1 2 3 4 5

beleza ?

thobias
-------
echo 9446046325380026818553633794429812592304650P | dc
-------
http://www.lcp.coppe.ufrj.br/~thobias

____________________________
|
| Against - HTML Mail
| Against - MS ATTACHMENTS
|
----------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]