- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl sort on a big file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 04:41 PM
тАО04-04-2003 04:41 PM
Need help in improving the sort in perl. I am reading a file full of records with pipe(|) delimited fields. I have about 13 fields in total and i am sorting the file on the first and third field.
In other words, I am sorting the records numerically on the first field and if it is same then sorting (string) on third field.
Below is the code i am using. Since our input files are in terms of GB (giga bytes) I would greatly appreciate any help in doing this better and faster.
open(DAT, $ARGV[0]) or die "Cannot open $ARGV[0] for read\n";
my @records = sort by_gst_date(
sub by_gst_date {
my @first = split(/\|/,$a);
my @second = split(/\|/,$b);
$first[0] <=> $second[0]
or
$first[2] cmp $second[2]
}
Thank you for your help.
Regards,
Chandra
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 04:58 PM
тАО04-04-2003 04:58 PM
Re: Perl sort on a big file
sort -t \| -kn1 -kn3 SomeBig_file
To reverse the sort, just add -r to the sort options. Note that you need to escape the pipe symbol with a backslash as it has special meaning to the shell.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 05:04 PM
тАО04-04-2003 05:04 PM
Re: Perl sort on a big file
Thank you,
Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 05:13 PM
тАО04-04-2003 05:13 PM
Re: Perl sort on a big file
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2003 05:18 PM
тАО04-04-2003 05:18 PM
Re: Perl sort on a big file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2003 11:26 AM
тАО04-05-2003 11:26 AM
Solutionmy @recs = map { $_->[1] }
sort { $a->[0] cmp $b->[0] }
map { [ (pack "sA*", (split/\|/)[0,2]), $_ ]}
bloody fast and efficient. (warning: written from brain, not tested)
Beats the hell out of external sort.
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2003 11:37 AM
тАО04-05-2003 11:37 AM
Re: Perl sort on a big file
up till 5.6.1 it's indeed quicksort.
Enjoy, have FUN! H.Merijn