sorting(both Ascending & Descending) files based on multiple fields
Hi All,
I am encountered with a problem while sorting a file based on multiple columns . I need to sort like:
(field2,ascending) , (field3,ascending) ,(field8,descending) , (field7,ascending),(field13,ascending).
So far i was sorting only in ascending order but here i need to use one descending field also.
Please see the sample text which needs to be sorted based on above rule.The text is TAB delimited.
Previously i was using sort like
sort -t "`echo -e "\t"`" +1 -2 +2 -3 >tmp This sort file using 2nd and 3rd field in ascending order only having TAB as delimiter.
Please help me to sort it out.
Thanks
Neeraj
Last edited by radoulov; 05-18-2009 at 08:56 AM..
Reason: added code tags
Hi,
I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting.
I understand that there is a previous... (8 Replies)
Dear All,
I have below attached file in which i have many nos, i want the last ascending order nos. The brief description is given below.
File
315
381
432
315
381
432
315
381
432
315
381
432
315
381
432 (6 Replies)
Hi,
I have a requirement whereby I have to sort a flat file based on Multiple Columns (similar to ORDER BY Clause of Oracle). I am getting 10 columns in the flat file and I want the file to be sorted on 1st, 3rd, 4th, 7th and 9th columns in ascending order. The flat file is pipe seperated.
Any... (15 Replies)
I have a bash script which takes a log file with each record separated by a #. The records have multiple fields but field $1 is always the date and time. When the script is run it prints the record just fine from oldest to newest. I need to have records print out from newest first.
Here is the... (7 Replies)
Hello,
I have data where words are separated by a delimiter. In this case "="
The number of delimiters in a line can vary from 4to 8. The norm is 4.
Is it possible to have a script where the file could be separated starting with highest number of delimiters and ending with the lowest
An... (8 Replies)
I want to sort values of a hash in ascending order.
my %records;
for my $value (sort values %records){print $value,"\n";}
When I use the above code I get values in this order: 1,10,11,2,3,4,5,6,7,8,9. But, I need values in my output in this order: 1,2,3,4,5,6,7,8,9,10,11.
Can Someone... (1 Reply)
Hi,
I have this single file with a number of sequence inside it of format
>string1
data
>string100
data
>string10
.....
>string5
...
>string67
......
the dots represent data.
I wanted to get the sequences arranged in ascending order like
>string1
data
>string5 (5 Replies)
Hi,
I am trying to sort the following file in descending order of its fourth column.
2 1 363828 -2.423225e-03
3 1 363828 4.132763e-03
3 2 363828 8.150133e-03
4 1 363828 4.126890e-03
I use
sort -k4,4g -r input.txt > output.txt ... (1 Reply)
Discussion started by: evelibertine
1 Replies
LEARN ABOUT DEBIAN
sort-dctrl
SORT-DCTRL(1) Debian user's manual SORT-DCTRL(1)NAME
sort-dctrl - sort Debian control files
SYNOPSIS
sort-dctrl [options] [ file ... ]
sort-dctrl --copying | --help | --version | -ChV
DESCRIPTION
The sort-dctrl program sorts Debian control files according to specified criteria.
A Debian control (dctrl) file is a semistructured single-table database stored in a machine-parseable text file. Such a database consists
of a set of records; each record is a mapping from field names to field content. Textually, records are separated by empty lines, while
each field is encoded as one or more nonempty lines inside a record. A field starts with its name, followed by a colon, followed by the
field content. The colon must reside on the first line of the field, and the first line must start with no whitespace. Subsequent lines,
in contrast, always start with linear whitespace (one or more space or tab characters).
The sort-dctrl program recognizes two field types: string fields and version fields. Version fields act also as numeric fields. String
fields are compared according to strict lexicographical octet-by-octet comparison, after ignoring any initial whitespace after the colon.
Version fields are parsed and compared as Debian version numbers. When comparing version numbers, if a field content does not in fact con-
form to the version number syntax, it compares less than any field content that does conform, and equal to any other nonconforming field
content. The sort-dctrl program assumes all fields are string fields unless told otherwise.
You can specify arbitrary number of keys for sorting, using the -k option. The keys are interpreted in a descending order of priority: the
first key specified is primary, the second key specified is secondary, and so on. If two records compare equal under the primary key, then
they are compared under the secondary key, and so on. If no keys are specified, a default key is assumed (the "Package" field with no mod-
ifiers).
OPTIONS -k keyspec, --key-spec=keyspec
Specify one or more keys for sorting. You may specify this option any number of times. The keyspec argument consists of a comma-
separated list of key specifications. Each key specification consists of the name of the field that serves as the key, optionally
followed by a colon and key modifiers. The following key modifiers are supported:
r Invert the comparison for this key, reversing the sorting order.
v Treat this field as a version number field.
n Treat this field as numeric, which currently is synonymous with v.
-q, --quiet, --silent
Output nothing to the standard output stream. Instead, exit immediately after finding the first match.
-l level, --errorlevel=level
Set log level to level. level is one of fatal, important, informational and debug, but the last may not be available, depending on
the compile-time options. These categories are given here in order; every message that is emitted when fatal is in effect, will be
emitted in the important error level, and so on. The default is important.
-V, --version
Print out version information.
-C, --copying
Print out the copyright license. This produces much output; be sure to redirect or pipe it somewhere (such as your favourite
pager).
-h, --help
Print out a help summary.
EXAMPLES
Here are some sample invocations of the program:
sort-dctrl /var/lib/dpkg/available
Output the dpkg available file sorted by the package name.
sort-dctrl -k Version:v /var/lib/dpkg/available
Output the dpkg available file sorted in ascending order of version numbers.
sort-dctrl -k Version:vr /var/lib/dpkg/available
Output the dpkg available file sorted in descending order of version numbers.
sort-dctrl -k Package,Version:v /var/lib/dpkg/available
Output the dpkg available file sorted primarily in ascending order of package names and secondarily in descending order of version
numbers.
sort-dctrl -k Installed-Size:n,Size:nr /var/lib/dpkg/available
Output the dpkg available file sorted primarily in ascending order of installation sizes and secondarily in descending order of
package sizes.
AUTHOR
The program and this manual page were written by Antti-Juhani Kaijanaho <ajk@debian.org>.
SEE ALSO
Debian Policy Manual. Published as the Debian package debian-policy. Also available in the Debian website.
grep-dctrl(1)Debian Project 2005-06-08 SORT-DCTRL(1)