- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- sorting help urgent
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
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
тАО11-29-2006 10:27 PM
тАО11-29-2006 10:27 PM
I need the output to be sorted by the line number along with the record number as well.
(both line and record number are specified in the file).
for the lines where field number is not given, they shud be sorted along the line sorting.
Solved! Go to Solution.
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-29-2006 10:58 PM
тАО11-29-2006 10:58 PM
Solutionmy solution would be delimiter replacement:
#!/usr/bin/sh
sed "s/- line/*/" data > data2
sed "s/,field/*/" data2 > data3
sort -t'*' -k 2,2n -k 3,3n data3 > data4
sed "s/*/- line/" data4 > data5
sed "s/*/,field/" data5 > data6
cat data6
If you input file is called data it substitues the "- line" with a "*" and repeats with ",field".
Then a sort is carried out to sort first on line, then on field.
Then the placeholders are replaced with their initial values.
You need to use a unique delimiter ! Base din your inputfile I used "*", you may need to use something else.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-30-2006 12:35 AM
тАО11-30-2006 12:35 AM
Re: sorting help urgent
Here's a simple solution:
# cat ./filter
#!/usr/bin/perl
use strict;
use warnings;
my @list;
my $line;
my $field;
while (<>) {
$line = m/line\s(\d+)/ ? $1 : 0;
$field = m/field\s(\d+)/ ? $1 : 0;
push @list, sprintf "%6d%6d%s", $line, $field, $_;
}
@list = sort @list;
for $line (@list) {
print substr( $line, 12 );
}
1;
...Run this passing your input file to be sorted:
# ./filter file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-30-2006 04:51 AM
тАО11-30-2006 04:51 AM
Re: sorting help urgent
awk -F"-" '{
gsub("[\",]"," ",$NF)
split($NF,z," ")
ml < z[2] ? ml=z[2] : ml
mr < z[4] ? mr=z[4] : mr
z[4] ? x[z[2]""z[4]]=$0 : x[z[2]""0]=$0
} END {
for (i=0;i
print x[i""j]
}' file
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-30-2006 05:19 AM
тАО11-30-2006 05:19 AM
Re: sorting help urgent
What about:
$sort -k9,9n -k10,10n data
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-30-2006 02:27 PM
тАО11-30-2006 02:27 PM
Re: sorting help urgent
$ sort -t- -k2,2 283372.txt
Unfortunately it does an ascii sort, not numeric. But Peter has solved that problem.
In Peter's solution, you can combine the first two seds and the last two:
#!/usr/bin/sh
sed -e 's/- line/*/' -e 's/,field/*/' data |
sort -t'*' -k2,2n -k3,3n |
sed -e 's/*/- line/"' -e 's/*/,field/'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-06-2006 01:47 AM
тАО12-06-2006 01:47 AM
Re: sorting help urgent
I would respectively ask, "Didn't you find the other solutions with merit? Did you try any of them?
...JRF...