incorrectly sorted file with snow leopard sort

View: New views
9 Messages — Rating Filter:   Alert me  

incorrectly sorted file with snow leopard sort

by emmanuel poirier-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message




list-of-groups-greetings.txt (758 bytes) Download Attachment

Re: incorrectly sorted file with snow leopard sort

by Kamil Dudka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 03 of November 2009 19:23:18 emmanuel poirier wrote:
> Attachment: list-of-groups-greetings.txt

$ cat list-of-groups-greetings.txt | tr -d "\r" | sort

Kamil



Re: incorrectly sorted file with snow leopard sort

by Eric Blake :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Kamil Dudka on 11/3/2009 1:16 PM:
> On Tuesday 03 of November 2009 19:23:18 emmanuel poirier wrote:
>> Attachment: list-of-groups-greetings.txt
>
> $ cat list-of-groups-greetings.txt | tr -d "\r" | sort

Useless use of cat.

tr -d "\r" < list-of-groups-greetings.txt | sort

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrw3/wACgkQ84KuGfSFAYC5igCgsh66IGswaEAoJkZV5bXd6gMV
8jYAoK7g3E/eKGlsWzqjI9egEpumOTlo
=DJym
-----END PGP SIGNATURE-----



Re: incorrectly sorted file with snow leopard sort

by Eric Blake :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 11/3/2009 6:59 PM:
> According to Kamil Dudka on 11/3/2009 1:16 PM:
>> On Tuesday 03 of November 2009 19:23:18 emmanuel poirier wrote:
>>> Attachment: list-of-groups-greetings.txt
>> $ cat list-of-groups-greetings.txt | tr -d "\r" | sort
>
> Useless use of cat.
>
> tr -d "\r" < list-of-groups-greetings.txt | sort

Also, "\r" is not portable - some shells treat it as "r", others as "\\r".
 For portability, use:

tr -d '\r' < list-of-groups-greetings.txt | sort

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrw4QcACgkQ84KuGfSFAYDV6QCdGC0JALmQL4N51rUeiZQK6dZX
C0QAoJROHxSOjqC/PbSVW2vwQI2uKOXs
=Rocb
-----END PGP SIGNATURE-----



Parent Message unknown Re: incorrectly sorted file with snow leopard sort

by Kamil Dudka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 03 of November 2009 23:41:29 emmanuel poirier wrote:
> And again the result is not good. -> Andromeda is stuck to Alcatraz on the
> same line, and at the end I got skidrow stuck with virtual dreams

It depends on what you wish to do with the \r. You can also replace it by
either spaces or newlines:

$ tr '\r' ' ' < list-of-groups-greetings.txt | sort
$ tr '\r' '\n' < list-of-groups-greetings.txt | sort

Kamil



Re: incorrectly sorted file with snow leopard sort

by Bauke Jan Douma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eric Blake wrote on 11/04/2009 02:59 AM:

>> $ cat list-of-groups-greetings.txt | tr -d "\r" | sort
>
> Useless use of cat.
>
> tr -d "\r" < list-of-groups-greetings.txt | sort

Useless maybe, but then again maybe the user won some time
by it. I often wind up with constructs like this.

Many times, you do 'less /path/to/file', then right after you
may want to run sed or grep on it, in which case I usually
find it quicker to edit the previous command-line as little
as I can, and just attach the grep or sed or whatever-command
to it: 'less /path/to/file | grep regex'.

An many times --this may be hurtful ;-)-- I wind up doing 'cat
file' on too large a file, followed by a quick command-
line edit that gives me: 'cat file | less'.

Basically, I think I (my fingers?, my eyes?) have trouble
getting to the '<'. I'm not a touch typist by any means.

bjd



Re: incorrectly sorted file with snow leopard sort

by Bauke Jan Douma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Eric Blake wrote on 11/04/2009 02:59 AM:

 >> $ cat list-of-groups-greetings.txt | tr -d "\r" | sort
 >
 > Useless use of cat.
 >
 > tr -d "\r" < list-of-groups-greetings.txt | sort

Useless maybe, but then again maybe the user won some time
by it. I often wind up with constructs like this.

Many times, you do 'less /path/to/file', then right after you
may want to run sed or grep on it, in which case I usually
find it quicker to edit the previous command-line as little
as I can, and just attach the grep or sed or whatever-command
to it: 'less /path/to/file | grep regex'.

And many times --this may be hurtful ;-) -- I wind up doing 'cat
file' on too large a file, followed by a quick command-
line edit that gives me: 'cat file | less'.

Basically, I think I (my fingers?, my eyes?) have trouble
getting to the '<'. I'm not a touch typist by any means.

bjd




Re: incorrectly sorted file with snow leopard sort

by Bob Proulx :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bauke Jan Douma wrote:

> Eric Blake wrote on 11/04/2009 02:59 AM:
>> Useless use of cat.
>> tr -d "\r" < list-of-groups-greetings.txt | sort
>
> Useless maybe, but then again maybe the user won some time
> by it. I often wind up with constructs like this.
>
> Many times, you do 'less /path/to/file', then right after you
> may want to run sed or grep on it, in which case I usually
> find it quicker to edit the previous command-line as little
> as I can, and just attach the grep or sed or whatever-command
> to it: 'less /path/to/file | grep regex'.
>
> An many times --this may be hurtful ;-)-- I wind up doing 'cat
> file' on too large a file, followed by a quick command-
> line edit that gives me: 'cat file | less'.
>
> Basically, I think I (my fingers?, my eyes?) have trouble
> getting to the '<'. I'm not a touch typist by any means.

I don't think anyone worries about anything written on the command
line.  If you are typing it and hitting enter then do whatever makes
sense to you.

The problem is that those command lines tend to make their way into
scripts.  It is in scripts that some of these constructs cause more
problems.  Doing character I/O can actually be quite CPU intensive.  I
have often benchmarked and found large optimizations there.  It does
keep those multicore processors busy! :-)

Bob



Re: incorrectly sorted file with snow leopard sort

by Andreas Schwab-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bauke Jan Douma <bjdouma@...> writes:

> Eric Blake wrote on 11/04/2009 02:59 AM:
>
>>> $ cat list-of-groups-greetings.txt | tr -d "\r" | sort
>>
>> Useless use of cat.
>>
>> tr -d "\r" < list-of-groups-greetings.txt | sort
>
> Useless maybe, but then again maybe the user won some time
> by it. I often wind up with constructs like this.
>
> Many times, you do 'less /path/to/file', then right after you
> may want to run sed or grep on it, in which case I usually
> find it quicker to edit the previous command-line as little
> as I can, and just attach the grep or sed or whatever-command
> to it: 'less /path/to/file | grep regex'.

$ < list-of-groups-greetings.txt tr -d "\r" | sort

Andreas.

--
Andreas Schwab, schwab@...
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."