I have used sort -k1 -n data.txt > output.txt command on a large text data file with over 1,000,000 rows. The command managed to sort the data but the code did not read data according to sequence of occurrence. Given below are the first five lines of the data I need to sort;
I do have repeated numbers on the first columns at different places. I would want that the sort read the data which begins with 1, 2, 3,...,n, n+1 in the order of occurrence within the text. At the moment yes, the data is sorted but it takes maybe data which begins with 1 on line 147 and place it on line 2 yet there is data which begins with 1 in say line 51.
I would appreciate further help with this.
Last edited by rbatte1; 02-08-2017 at 06:34 AM..
Reason: Changed some CODE tags to ICODE
Can someone please tell me how to sort a file, based on a particular position within the file?
I have a line sequential file that is 152 bytes per record, in which i need to sort the file based on the numeric data in positions 142-152.
I have done the "man sort" command and see the -k option... (1 Reply)
Hi,
I am going to sort a huge flat file using sort command, this file is about 36 million lines, 179 fields delimitered by Ctrl B (002). eg.
1^B198709.....
17^B200301....
3^B196511....
.....
I want this file being sorted by the first field, the result is like :
1^B198709........ (2 Replies)
Hi
IŽd like to get a few explanations about how the sort command works when cascading the options.
cscyabl@comet:(develop)> more file
2:A2
2:A1
5:A2
5:A2
10:A1
cscyabl@comet:(develop)> sort -n -u file
2:A1
5:A2
10:A1
cscyabl@comet:(develop)> sort -u -n file
2:A1
5:A2
10:A1... (8 Replies)
Hi i have a file containing ip addresses and want to sort those IP addresses in the ascending order.
file (match.txt) contents are:
192.168.0.100
192.168.0.16
192.168.0.10
192.168.0.23
192.168.0.2
192.168.0.3
192.168.0.1
192.168.0.222
i tried:
sort -n match.txt
output is :... (3 Replies)
Hi to all.
I'm trying to sort this with the Unix command sort.
user1:12345678:3.5:2.5:8:1:2:3
user2:12345679:4.5:3.5:8:1:3:2
user3:12345687:5.5:2.5:6:1:3:2
user4:12345670:5.5:2.5:5:3:2:1
user5:12345671:2.5:5.5:7:2:3:1
I need to get this:
user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
I have file ipaddress.txt
192.168.1.25
127.3.9.12
192.168.12.1
127.21.2.3
127.92.80.6
192.168.4.5
I want to sort as
127.3.9.12
127.21.2.3
127.92.80.6
192.168.1.25
192.168.12.1
192.168.4.5
So what sort command do I have to use. (1 Reply)
I have a file with the following content:-
181268525,0640613864,B,113,22-dec-2011 14:12:08,
181268525,0640613864,C,113,25-dec-2011 14:18:50,
181268525,0640613864,L,113,26-dec-2011 14:07:46,
181268525,0640613864,X,113,01-jan-2012 16:57:45,
181268525,0640613864,X,113,04-jan-2012 14:13:27,... (3 Replies)
I have an input like
4.3.6.66
4.3.6.67
4.3.6.70
4.3.6.25
4.3.6.15
4.3.6.54
4.3.6.44
4.3.6.34
4.3.6.24
4.3.6.14
4.3.6.53
4.3.6.43
4.3.6.49
4.3.6.33
4.3.6.52
4.3.6.19
4.3.6.58
4.3.6.42 (5 Replies)
Discussion started by: dnam9917
5 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)