Introduction to the sort command in AIX and use the [plain] www.2cto.com sort command to sort many different fields in different column order. The sort command is as follows: sort-cmu-o output_file [other options] + pos1 + pos2 input_files-c: test whether the file has been sorted-m: merge two sort files-u: delete all duplicate rows-o: other options for storing output file names of sort results:-B: When sorting by fields, ignore the first space-n: specifies that the sorting is a numerical sorting in the field-t: domain separator, use a non-space or tab key to separate the domain-r: reverse or reverse order + n: n as the domain number. Use this domain number to start sorting. n: n is the domain number, the secondary domain is ignored during sorting and comparison. Generally, pos1 is used with + n: passed to m, n; m is the domain number, and n is the number of start sorting characters; for example, 4 and 6 are 5th fields, and the domain separator www.2cto.com starts with 7th characters. By default, sort considers a space or a series of spaces as separators. The sorting key. The first field is the sorting key 1, the second field is the sorting key 2, and so on. Sort by sort key 1, sort by sort key 2, and so on. During sorting, each domain is compared by the ASCII code of characters, numbers, or symbols. The ASCII value of spaces is 32. Classify by Numeric Fields and add n to the domain number. File video.txt pg video.txt Boys in Company C: HK: 192: 2192 Alien: HK: 119: 1982 The Hill: KL: 63: 2972 Aliens: HK: 532: 4892 Star Wars: HK: 301: 4102 A Few Good Men: KL: 445: 5851 Toy Story: HK: 239: 3972 A google: HK where ":" Is the domain separator. Use "-t: "The connected domains are separated. Forward order: pg video.txt Boys in Company C: HK: 192: 2192 Alien: HK: 119: 1982 The Hill: KL: 63: 2972 Aliens: HK: 532: 4892 Star Wars: HK: 301: 4102 A Few Good Men: KL: 445: 5851 Toy Story: HK: 239: 3972 A google: HK in reverse order: sort-t:-r video.txt Toy Story: HK: 239: 3972 The Hill: KL: 63: 2972 Star Wars: HK: 301: 4102 Boys in Company C: HK: 192: 2192 Aliens: HK: 532: 4892 Alien: HK: 119: 1982 A google: hk a Few Good Men: KL: 445: 5851 www.2cto.com Sort the first domain by the specified domain: sort-t: + 1 video.txt A google: HK Alien: HK: 119: 1982 Boys in Company C: HK: 192: 2192 Toy Story: HK: 239: 3972 Star Wars: HK: 301: 4102 Aliens: HK: 532: 4892 ① A Few Good Men: KL: 445: 5851 ② The Hill: KL: 63: 2972 second domain: sort-t: + 2 video.txt A google: HK Alien: HK: 119: 1982 Boys in Company C: HK: 192: 2192 Toy Story: HK: 239: 3972 Star Wars: HK: 301: 4102 A Few Good Men: KL: 445: 5851 ② Aliens: HK: 532: 4892 ① The Hill: KL: 63: 2972 third domain: sort-t: + 3n video.txt A google: HK Alien: HK: 119: 1982 Boys in Company C: HK: 192: 2192 The Hill: KL: 63: 2972 Toy Story: HK: 239: 3972 Star Wars: HK: 301: 4102 Aliens: HK: 532: 4892 A Few Good Men: KL: 445: 5851 remove duplicate rows. We will first add duplicate rows to the file: pg video.txt Boys in Company C: HK: 192: 2192... A google: HK use the-u option to remove duplicate rows: sort-u video.txt A Few Good Men: KL: 445: 5851 A google: HK Alien: HK: 119: 1982 Aliens: HK: 532: 4892 Boys in Company C: HK: 192: 2192 Star Wars: HK: 301: 4102 The Hill: KL: 63: 2972 Toy Story: HK: 239: 3972 use k to sort the key values and number the domain in order. The first domain is k1, the second domain is k2, and so on. Sort By 4th domains first, and sort by 1st domains sort-t:-r-k4-k1 video.txt A Few Good Men: KL: 445: 5851 Aliens: HK: 532: 4892 Star Wars: HK: 301: 4102 Toy Story: HK: 239: 3972 The Hill: KL: 63: 2972 Boys in Company C: HK: 192: 2192 Alien: HK: 119: 1982 ① A google: HK: 301: 1982 ② A google: HK www.2cto.com pos usage: Specifies the location of letters in the domain. Format: sort + field_number.characters_in meaning: sort from the character characters_in of field_number. For example: Field0 Field1 Field2 Field3 Aliens h k 1 L 532 4892 0 1 2 3 sort-t: + 1.2 video.txt Aliens: HK1l: 532: 4892 A google: HK10: 301: 1982 The Hill: KL23: 63: 2972 Star Wars: HK38: 301: 4102 Boys in Company C: HK48: 192: 2192 Alien: HK57: 119: 1982 Toy Story: HK65: 239: 3972 A Few Good Men: KL87: 445: 5851 domain IDs start from 0, the subscript of the first field is 0, similar to the array subscript in C language starting from 0. Sort by The second character of The first domain: sort-t: + 0.1 video.txt A Few Good Men: KL87: 445: 5851 A google: HK10: 301: 1982 The Hill: KL23: 63: 2972 Alien: HK57: 119: 1982 Aliens: HK1l: 532: 4892 Toy Story: HK65: 239: 3972 Boys in Company C: HK48: 192: 2192 Star Wars: HK38: 301: 4102 displays the first few rows or the last few rows after sorting by 4th fields, and then displays the first two rows: sort-t: -k4 video.txt | head-2 A google: HK10: 301: 1982 Alien: HK57: 119: 1982 sort data from the third character of the 1st domains and view the last row of data: sort-t: + 0.2 video.txt | t Ail-1 Boys in Company C: HK48: 192: 2192 in addition, you can use the head and tail commands to view one or more lines of data in the header or tail of the file. Pg video.txt Boys in Company C: HK48: 192: 2192 Alien: HK57: 119: 1982 The Hill: KL23: 63: 2972 Aliens: HK1l: 532: 4892 Star Wars: HK38: 301: 4102 A Few Good Men: KL87: 445: 5851 Toy Story: HK65: 239: 3972 A google: HK10: 301: 1982 1.20.video.txt the first three lines of the file: head-3 video.txt Boys in Company C: HK48: 192: 2192 Alien: HK57: 119: 1982 The Hill: KL23: 63: 2972 2.20.video.txt The last two lines of The file: tail-2 video.txt Toy Story: HK65: 239: 3972 A google: HK10: 3 01: 1982 3. head and tail commands. If no line is specified, 10 lines are displayed by default. Run the following command in combination with the awk command: sort-t:-k4 video.txt | tail-1 | awk-F: '{print "The highest is" $4}' The highest is 5851 use-m to merge The two files. Format: sort-m file1 file2 pg video2.txt Crimson Tide: 134: 2031 Die Hard: 152: 2981 pg video.txt Boys in Company C: HK48: 192: 2192 Alien: HK57: 119: 1982 The Hill: KL23: 63: 2972 Aliens: HK1l: 532: 4892 Star Wars: HK38: 301: 4102 A Few Good Men: KL87: 445: 5851 Toy Story: HK65: 239: 3972 A google: HK10: 301: 198 2 merge: sort-t:-m video2.txt video.txt Boys in Company C: HK48: 192: 2192 Alien: HK57: 119: 1982 Crimson Tide: 134: 2031 ① Die Hard: 152: 2981 ② The Hill: KL23: 63: 2972 Aliens: HK1l: 532: 4892 Star Wars: HK38: 301: 4102 A Few Good Men: KL87: 445: 5851 Toy Story: HK65: 239: 3972 A google: HK10: 301: 1982 view disk information, df | sort + 4/dev/boot 30720 10693 20027 35%/stand/dev/root 72986472 48856763 24129709/Filesystem sorted by the fourth domain 1024-blocks Used Available Capacity Mounted on: sorts the IP addresses. Pg iplist 191.168.1.55 Scott 191.168.2.36 Tim Cook 191.168.2.56 Davaid 191.168.1.80 Albert 191.168.1.20 Thomas 191.168.2.155 _ yeeXun 191.168.2.253 J. sort the IP addresses under Wong ". "As a separator, four fields are separated. First, 3rd fields are sorted, and then 4th fields are sorted. Note: The number field 0 indicates the first domain, followed by the letter "n ". Sort-t. + 2n + 3n iplist 191.168.1.20 Thomas 191.168.1.55 Scott 191.168.1.80 Albert 191.168.2.155 _ yeeXun Jun J. Wong 191.168.2.36 Tim Cook 191.168.2.56 Davaid -- the end --