The result you get is exactly as specified - sorted by field 1 (all lines identical), then field 3. I don't see column 2 sorted - it's just random, as its results are unspecified. To keep the original file order once all keys are consumed, try Corona688's approach, or, quite similar:
The problem with your sample file is a trailing space in line one that influences the key 4 - use -n to overcome.
hey,
I have a file that looks smthng like this:
/*--- abcd_0050 ---*/
asdfjk
adsfkja
lkjljgafsd
/*---abcd_0005 ---*/
lkjkljbfkgj
ldfksjgf
dfkgfjb
/*-- abcd_0055--*/
klhfdghd
dflkjgd
jfdg
I would like it to be sorted so that it looks like this:
/*---abcd_0005 ---*/
lkjkljbfkgj (9 Replies)
how can i sort the next list just by look at the numbers (ignore letters)
example:
abc123
dff4f
aaa2aa
bbbb55555bb
output:
aaa2aa
dff4f
abc123
bbbb55555bb (1 Reply)
i have list of files:
Wang De Wong CVPR 09.pdf
Yaacob AFGR 99 Second edition.pdf
Shimon CVPR 01.pdf
Den CCC 97 long one.pdf
Ronald De Bour CSPP 04.pdf
.....
how can i sort this directory so the output will be in the next format:
<year>\t<conference/journal>\t<author list> - t is tab
(its... (1 Reply)
i have list of files:
Wang De Wong CVPR 09.pdf
Yaacob AFGR 99 Second edition.pdf
Shimon CVPR 01.pdf
Den CCC 97 long one.pdf
Ronald De Bour CSPP 04.pdf
.....
how can i sort this directory so the output will be in the next format:
<year>\t<conference/journal>\t<author list> - t is tab
(its... (1 Reply)
Let's say that I have a database that I call part ID. This database has the following grouping:
Dart1=4
Dart2=8
Dart3=12
Fork1=68
Fork2=72
Fork3=64
Bike1=28
Bike2=24
Bike3=20
Car1=44
Car2=40
Car3=36
I want to write a program that would read this database and tell me when the... (19 Replies)
hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this;
192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible... (1 Reply)
hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this;
192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible... (1 Reply)
Hi, I have posted related topic but as i continue the research I find more need to sort the data.
AS(2607:f278:4101:11:dead:beef:f00f:f), AS786 AS6453 AS7575 AS7922
AS(2607:f2e0:f:1db::16), AS786 AS3257 AS36252
AS786 AS3257 AS36252
AS(2607:f2f8:1700::2), AS786 AS6939 AS25795 ... (6 Replies)
Hi all,
Does anyone can help me the following question? I would like to write an AWK script.
In the following input file, each number in "start" is paired with numbers in column "end".
No Start End
A 22,222,33,22,1233,3232,44 555,333,222,55,1235,3235,66... (7 Replies)
Hi, Please i need help in writing an 'awk' script in sorting the following data;
traceroute6 to 2001:1ba0:2a0:5965:0:30:24:1 (2001:1ba0:2a0:5965:0:30:24:1) from 2001:418:1::62, 64 hops max, 16 byte packets
1 2001:418:1::4 0.342 ms
2 2001:418:1::1 0.630 ms
3 2001:504:16::1b1b 0.393 ms
4... (6 Replies)
Discussion started by: sam127
6 Replies
LEARN ABOUT ULTRIX
sort
sort(1) General Commands Manual sort(1)Name
sort - sort file data
Syntax
sort [options] [-k keydef] [+pos1[-pos2]] [file...]
Description
The command sorts lines of all the named files together and writes the result on the standard output. The name `-' means the standard
input. If no input files are named, the standard input is sorted.
Options
The default sort key is an entire line. Default ordering is lexicographic by bytes in machine collating sequence. The ordering is
affected globally by the following options, one or more of which may appear.
-b Ignores leading blanks (spaces and tabs) in field comparisons.
-d Sorts data according to dictionary ordering: letters, digits, and blanks only.
-f Folds uppercase to lowercase while sorting.
-i Ignore characters outside the ASCII range 040-0176 in nonnumeric comparisons.
-k keydef The keydefargument is a key field definition. The format is field_start, [field_end] [type], where field_start and field_end
are the definition of the restricted search key, and type is a modifier from the option list [bdfinr]. These modifiers have the
functionality, for this key only, that their command line counter-parts have for the entire record.
-n Sorts fields with numbers numerically. An initial numeric string, consisting of optional blanks, optional minus sign, and zero
or more digits with optional decimal point, is sorted by arithmetic value. (Note that -0 is taken to be equal to 0.) Option n
implies option b.
-r Reverses the sense of comparisons.
-tx Uses specified character as field separator.
The notation +pos1 -pos2 restricts a sort key to a field beginning at pos1 and ending just before pos2. Pos1 and pos2 each have the form
m.n, optionally followed by one or more of the options bdfinr, where m tells a number of fields to skip from the beginning of the line and
n tells a number of characters to skip further. If any options are present they override all the global ordering options for this key. If
the b option is in effect n is counted from the first nonblank in the field; b is attached independently to pos2. A missing .n means .0; a
missing -pos2 means the end of the line. Under the -tx option, fields are strings separated by x; otherwise fields are nonempty nonblank
strings separated by blanks.
When there are multiple sort keys, later keys are compared only after all earlier keys compare equal. Lines that otherwise compare equal
are ordered with all bytes significant.
These are additional options:
-c Checks sorting order and displays output only if out of order.
-m Merges previously sorted data.
-o name Uses specified file as output file. This file may be the same as one of the inputs.
-T dir Uses specified directory to build temporary files.
-u Suppresses all duplicate entries. Ignored bytes and bytes outside keys do not participate in this comparison.
Examples
Print in alphabetical order all the unique spellings in a list of words. Capitalized words differ from uncapitalized.
sort -u +0f +0 list
Print the password file, sorted by user id number (the 3rd colon-separated field).
sort -t: +2n /etc/passwd
Print the first instance of each month in an already sorted file of (month day) entries. The options -um with just one input file make the
choice of a unique representative from a set of equal lines predictable.
sort -um +0 -1 dates
Restrictions
Very long lines are silently truncated.
Diagnostics
Comments and exits with nonzero status for various trouble conditions and for disorder discovered under option c.
Files
/usr/tmp/stm*, /tmp/* first and second tries for temporary files
See Alsocomm(1), join(1), rev(1), uniq(1)sort(1)