Did you try "sort"? I often use it with the -u argument to get rid of duplicates. The most common duplicate is a blank line and when you sort them all to the beginning of a file, you have a huge amount of blank lines. ==Now for the vi fans out there!!!! I use sort very often directly from vi. This key sequence is a typical one for me: Use arrow keys to position cursor at start of block to sort. ma (Mark this spot as a) Use arrow keys to position cursor at start of block to sort. !'asort (! - filter, 'a - goto a, sort - filter to run) or to sort a whole file: 1G (goto first line of file !Gsort (! - filter, G - goto end of file, sort - filter to run) Greg Freemyer
Hi,
Does anyone know of an utilty that will take a text file and rearrange it into alphabetical order by line ( have been playing around with fonts and have a feeling that fonts.scale should be [alphabetical] and isn't).
Many thanks
Francesco
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Thanks - that looks ( from the manpage ) as if it will so fine Cheers Francesco
On Mon, 23 Dec 2002 11:05:07 -0500
Greg Freemyer
Did you try "sort"?
I often use it with the -u argument to get rid of duplicates.
Here's a perl script for you ################################################ #!/usr/bin/perl open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array; open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH; ############################################## -- use Perl; #powerful programmable prestidigitation
From: zentara
On Mon, 23 Dec 2002 11:05:07 -0500 Greg Freemyer
wrote: Did you try "sort"?
I often use it with the -u argument to get rid of duplicates.
Here's a perl script for you ################################################ #!/usr/bin/perl open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array; open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH; ##############################################
-- use Perl; #powerful programmable prestidigitation
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Thanks again and more -- Francesco
Here's a perl script for you ################################################ #!/usr/bin/perl open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array; open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH; ##############################################
Is that not just a very longhand way of saying: perl -e 'print sort <>' < file > file.sorted ? -- Australian Linux Technical Conference 2003: http://www.linux.conf.au/ Explain to your boss the benefits of you going...
On Tue, 24 Dec 2002 07:28:50 +0000
Derek Fountain
Here's a perl script for you ################################################ #!/usr/bin/perl open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array; open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH; ##############################################
Is that not just a very longhand way of saying:
perl -e 'print sort <>' < file > file.sorted
Yeah, but for some reason I have a hard time remembering 1-liners, this way, I can save the script and just run it on a file. It also explains what is happening better, in case you want to do some modifications. Some people like 1-liners, some don't. -- use Perl; #powerful programmable prestidigitation
Derek Fountain
Here's a perl script for you ################################################ #!/usr/bin/perl open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array; open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH; ##############################################
Is that not just a very longhand way of saying:
perl -e 'print sort <>' < file > file.sorted
Anyway, both don't sort according to the current locale while the command "sort" does. See perllocale: USING LOCALES The use locale pragma By default, Perl ignores the current locale. The "use locale" pragma tells Perl to use the current locale for some operations: The comparison operators ("lt", "le", "cmp", "ge", and "gt") and the POSIX string collation functions strcoll() and strxfrm() use "LC_COLLATE". sort() is also affected if used without an explicit comparison function, because it uses "cmp" by default. -- Alexandr.Malusek@imv.liu.se
Is that not just a very longhand way of saying:
perl -e 'print sort <>' < file > file.sorted
Anyway, both don't sort according to the current locale while the command "sort" does. See perllocale:
USING LOCALES The use locale pragma
By default, Perl ignores the current locale. The "use locale" pragma tells Perl to use the current locale for some operations:
The comparison operators ("lt", "le", "cmp", "ge", and "gt") and the POSIX string collation functions strcoll() and strxfrm() use "LC_COLLATE". sort() is also affected if used without an explicit comparison function, because it uses "cmp" by default.
Never knew that. I guess locales don't apply too much to people who work in English all of the time? Anyway, is this the fix?: perl -e 'use locale; print sort <>' < file > file.sorted Makes no difference on my machine with my test data of course. -- Australian Linux Technical Conference 2003: http://www.linux.conf.au/ Explain to your boss the benefits of you going...
Derek Fountain
perl -e 'print sort <>' < file > file.sorted
Anyway, both don't sort according to the current locale while the command "sort" does. See perllocale: ...
Never knew that. I guess locales don't apply too much to people who work in English all of the time?
Yes.
Anyway, is this the fix?:
perl -e 'use locale; print sort <>' < file > file.sorted
Yes. See the following: $ cat file B b a A $ export LC_ALL=cs_CZ # Czech language collation order $ perl -e 'print sort <>' < file A B a b $ perl -e 'use locale;print sort <>' < file A a B b To make it easy, I avoided accented characters. -- Alexandr.Malusek@imv.liu.se
Alexandr Malusek
I guess locales don't apply too much to people who work in English all of the time?
Yes.
I was very wrong here. Both en_US and en_GB collation order differs from the default POSIX C: $ export LC_ALL=en_US $ perl -e 'print sort <>' < file A B a b $ perl -e 'use locale; print sort <>' < file a A b B Perl programmers should keep it in mind. -- Alexandr.Malusek@imv.liu.se
On 24 Dec 2002 14:27:27 +0100
Alexandr Malusek
Both en_US and en_GB collation order differs from the default POSIX C: $ export LC_ALL=en_US
$ perl -e 'print sort <>' < file A B a b
$ perl -e 'use locale; print sort <>' < file a A b B
Perl programmers should keep it in mind.
Well here is even more to confuse us all. I run the following script, with and without use locales; and my output is A B Z a b z either way the same output. #!/usr/bin/perl -w #use locale; open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array; open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH; -- use Perl; #powerful programmable prestidigitation
zentara
On 24 Dec 2002 14:27:27 +0100 Alexandr Malusek
wrote: Both en_US and en_GB collation order differs from the default POSIX C:
Well here is even more to confuse us all. I run the following script, with and without use locales; and my output is A B Z a b z
I cannot reproduce your problem on my machines (SuSE 7.3, 8.1), the "use locale" command works according to the documentation there. Use the command "locale" to check LC_COLLATE is not set to POSIX but to "en_US" and that locales are installed. $ rpm -qf /usr/lib/locale/en_US/LC_COLLATE glibc-locale-2.2.5-151 -- Alexandr.Malusek@imv.liu.se
Thats correct capiton A is 65 ascii and lowercase a is 97 ascii.
As soon as I get my box back up Ill have to start learning perl it looks
like a fun language.
Any recommendations as to books for beginners.
CWSIV
On Tue, 24 Dec 2002 13:50:01 -0500 zentara
Perl programmers should keep it in mind.
Well here is even more to confuse us all. I run the following script, with and without use locales; and my output is A B Z a b z
either way the same output.
#!/usr/bin/perl -w #use locale; open (FH,"<$ARGV[0]") or die $!; @array = <FH>; my @sorted = sort @array;
open (FH,">$ARGV[0].sorted") or die $!; print FH @sorted; close FH;
-- use Perl; #powerful programmable prestidigitation
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
________________________________________________________________ Sign Up for Juno Platinum Internet Access Today Only $9.95 per month! Visit www.juno.com
On Fri, 27 Dec 2002 15:05:58 PST
Carl William Spitzer IV
As soon as I get my box back up Ill have to start learning perl it looks like a fun language.
Any recommendations as to books for beginners.
Your best buy is the Perl CD Bookshelf. Version 3 is the latest http://www.oreilly.com/catalog/perlcdbs3/ it's still a bit pricy though. But you do get all the books as html, so you can cut'n'paste code. It has a cumulative index too. I used the Bookshelf version 2. It is still pretty good for beginners, and you can get it at half.com for $7.00. That's unbelievably low compared to the ~100 for V3. Also, go to http://learn.perl.org/ and signup for their beginners list, for email, or subscribe to it via usenet(which is the best). You can ask away all the dumb beginner questions you might have, and some serious experts will answer you for FREE. :-) Just like a free school. -- use Perl; #powerful programmable prestidigitation
participants (6)
-
Alexandr Malusek
-
Carl William Spitzer IV
-
Derek Fountain
-
Francesco Scaglioni
-
Greg Freemyer
-
zentara