[Comprehensive explanation of Linux commands] 082. Complete collection of Linux commands: Detailed explanation and usage examples of apt-sortpkgs and sort

apt-sortpkgs

Tool for sorting package index files under Debian Linux

Additional information

apt-sortpkgsThe command is a simple tool for sorting package index files under Debian Linux.

grammar

apt-sortpkgs [选项] [参数]

options

  • -s: Sort using source index field;
  • -h: Display help information.

parameter

  • 文件: Specify the index file containing debian package information to be sorted.

sort

Sort all lines in a text file.

overview

sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F

The main purpose

Sort the contents of all input files and output them. When there is no file or the file is -, read standard input.

options

Sort options:

  • -b, --ignore-leading-blanks: Ignore leading whitespace.
  • -d, --dictionary-order: Only spaces, letters, and numbers are considered.
  • -f, --ignore-case: Consider lowercase letters as uppercase letters.
  • -g, --general-numeric-sort: Sort by numbers.
  • -i, --ignore-nonprinting: Exclude unprintable characters.
  • -M, --month-sort: Sort in the order of non-month, January, and December.
  • -h, --human-numeric-sort: Sort according to storage capacity (note the use of capital letters, for example: 2K 1G).
  • -n, --numeric-sort: Sort by numbers.
  • -R, --random-sort: Sort randomly but group identical rows.
  • --random-source=FILE: Get random length bytes from FILE.
  • -r, --reverse: Arrange the results in reverse order.
  • --sort=WORD: Sorted according to WORD, where: general-numeric is equivalent to -g, human-numeric is equivalent to -h, month is equivalent to -M, numeric is equivalent to -n, random is equivalent to -R, version is equivalent to -V.
  • -V, --version-sort: the natural ordering of (version) numbers in text.

other options:

  • --batch-size=NMERGE: Merge up to NMERGE inputs at a time; use temporary files for the excess.
  • -c, --check, --check=diagnose-first: Checks whether the input is sorted, this operation does not perform sorting.
  • -C, --check=quiet, --check=silent: Similar to the -c option, but does not output the first unsorted line.
  • --compress-program=PROG: Use PROG to compress temporary files; use PROG -d to decompress.
  • --debug: Comment lines used for sorting, sending alerts of suspicious usage to stderr.
  • --files0-from=F: Read all NUL-terminated file names from file F; if F is -, then read the names from standard input.
  • -k, --key=KEYDEF: Sort by a key; KEYDEF gives the position and type.
  • -m, --merge: Merge sorted files and no longer sort them.
  • -o, --output=FILE:Write results to FILE instead of standard output.
  • -s, --stable: Stable sorting by disabling the last comparison.
  • -S, --buffer-size=SIZE: Use SIZE as the memory cache size.
  • -t, --field-separator=SEP: Use SEP as the column separator.
  • -T, --temporary-directory=DIR: Use DIR as the temporary directory instead of $TMPDIR or /tmp; use this option multiple times to specify multiple temporary directories.
  • --parallel=N: Change the number of concurrently running sorts to N.
  • -u, --unique: Use -c at the same time to strictly check the sorting; do not use -c at the same time to output the deduplication result after sorting.
  • -z, --zero-terminated: Set the line terminator to NUL (empty) instead of newline.
  • --help: Display help information and exit.
  • --version: Display version information and exit.

The format of KEYDEF is

F[.C][OPTS][,F[.C][OPTS]]

Indicates the starting to ending position. F represents the number of the column, and C represents that OPTS is one or more characters in [bdfgiMhnRrV], which is used to override the current sorting option. Use the –debug option to diagnose incorrect usage.

Multiplicative suffix for SIZE

%:内存的1%;
b:1;
K:1024(默认);
剩余的M, G, T, P, E, Z, Y可以类推出来。

parameter

  • FILE(optional): The number of files to process, which can be any number.

return value

Returning 0 indicates success, returning a non-zero value indicates failure.

example

sort compares each line of the file/text as a unit. The comparison principle is to compare the ASCII code values ​​from the first character backward, and finally output them in ascending order.

root@[mail text]# cat sort.txt
aaa:10:1.1
ccc:30:3.3
ddd:40:4.4
bbb:20:2.2
eee:50:5.5
eee:50:5.5

[root@mail text]# sort sort.txt
aaa:10:1.1
bbb:20:2.2
ccc:30:3.3
ddd:40:4.4
eee:50:5.5
eee:50:5.5

To ignore identical lines use the -u option or uniq:

[root@mail text]# cat sort.txt
aaa:10:1.1
ccc:30:3.3
ddd:40:4.4
bbb:20:2.2
eee:50:5.5
eee:50:5.5

[root@mail text]# sort -u sort.txt
aaa:10:1.1
bbb:20:2.2
ccc:30:3.3
ddd:40:4.4
eee:50:5.5

[root@mail text]# uniq sort.txt
aaa:10:1.1
ccc:30:3.3
ddd:40:4.4
bbb:20:2.2
eee:50:5.5

Use of -n, -r, -k, -t options of sort:

[root@mail text]# cat sort.txt
AAA:BB:CC
aaa:30:1.6
ccc:50:3.3
ddd:20:4.2
bbb:10:2.5
eee:40:5.4
eee:60:5.1

# 将BB列按照数字从小到大顺序排列:
[root@mail text]# sort -nk 2 -t: sort.txt
AAA:BB:CC
bbb:10:2.5
ddd:20:4.2
aaa:30:1.6
eee:40:5.4
ccc:50:3.3
eee:60:5.1

# 将CC列数字从大到小顺序排列:
# -n是按照数字大小排序,-r是以相反顺序,-k是指定需要排序的栏位,-t指定栏位分隔符为冒号
[root@mail text]# sort -nrk 3 -t: sort.txt
eee:40:5.4
eee:60:5.1
ddd:20:4.2
ccc:50:3.3
bbb:10:2.5
aaa:30:1.6
AAA:BB:CC

Interpretation and examples of the -k option:

In-depth interpretation of the -k option:

FStart.CStart Modifier,FEnd.CEnd Modifier
-------Start--------,-------End--------
 FStart.CStart 选项  ,  FEnd.CEnd 选项

This syntax format can be divided into two parts by the commas, the Start part and the End part. The Start part consists of three parts. The Modifier part is the option part we mentioned before; we focus on FStart and C.Start in the Start part; C.Start can be omitted. If omitted, it means starting from the beginning of this domain. part begins. FStart.CStart, where FStart represents the field used, and CStart represents the first character of sorting starting from the character in the FStart field. Similarly, in the End section, you can set FEnd.CEnd. If you omit .CEnd or set it to 0, it means ending to the last character of this field.

Example: Sort from the second letter of the company’s English name:

$ sort -t ' ' -k 1.2 facebook.txt
baidu 100 5000
sohu 100 4500
google 110 5000
guge 50 3000

Interpretation: -k 1.2 is used, which means to sort the strings starting from the second character of the first field to the last character of this field. You will find that baidu is on the top of the list because the second letter is a. The second characters of sohu and google are both o, but the h of sohu comes before the o of google, so they are ranked second and third respectively. Guge can only be ranked fourth.

Example: Sort only by the second letter of the company's English name. If the same is done, sort by employee salary in descending order:

$ sort -t ' ' -k 1.2,1.2 -nrk 3,3 facebook.txt
baidu 100 5000
google 110 5000
sohu 100 4500
guge 50 3000

Interpretation: Since only the second letter is sorted, we use -k 1.2,1.2the representation, which means that we only sort the second letter (if you ask me -k 1.2why it doesn’t work? Of course it doesn’t work, because you omitted the End part, this This means that you will sort the string from the second letter to the last character of the field). To sort employee salaries, we also use this -k 3,3. This is the most accurate expression, which means that we only sort this field, because if you omit the following 3, it becomes that we start from the third field to the last field. The contents of the location are sorted.

Learn from scratchpython

[Learn python from scratch] 92. Use Python’s requests library to send HTTP requests and process responses
[Learn python from scratch] 91. Use decorators and dictionaries to manage request paths in a simple web application
[Learn python from scratch] 93. Use dictionary management Request path
[Learn python from scratch] 89. Use WSGI to build a simple and efficient Web server
[Learn python from scratch] 88. Detailed explanation of WSGI interface: realize simple and efficient web development
[Learn python from scratch] 87. Manually build an HTTP server in Python Implementation and multi-threaded concurrent processing
[Learn python from scratch] 86. In-depth understanding of the HTTP protocol and its role in browser and server communication
[Learn python from scratch] 85. Application of parallel computing technology in Python process pool
[Learn python from scratch] ] 84. In-depth understanding of threads and processes
[Learn python from scratch] 83. Python multi-process programming and the use of process pools
[Learn python from scratch] 82. Chat program implementation based on multi-threading
[Learn python from scratch] 81. Python more Application of thread communication and queue
[Learn python from scratch] 80. Thread access to global variables and thread safety issues
[Learn python from scratch] 79. Thread access to global variables and thread safety issues
[Learn python from scratch] 78. File download case
[ Learn python from scratch] 77. TCP server programming and precautions
[learn python from scratch] 76. Server and client: key components of network communication
[learn python from scratch] 75. TCP protocol: reliable connection-oriented transmission layer communication protocol
[Learn python from scratch] 74. UDP network program: Detailed explanation of port issues and binding information
[Learn python from scratch] 73. UDP network program - sending data
[Learn python from scratch] 72. In-depth understanding of Socket communication and creation of sockets Method
[Learn python from scratch] 71. Network ports and their functions
[Learn python from scratch] 70. Network communication methods and their applications: from direct communication to routers to connect multiple networks
[Learn python from scratch] 69. Network communication and IP address classification analysis
[Learn python from scratch] 68. Greedy and non-greedy modes in Python regular expressions
[Learn python from scratch] 67. The re module in Python: regular replacement and advanced matching technology
[Learn python from scratch] 66 .In-depth understanding of regular expressions: a powerful tool for pattern matching and text processing
[Learn python from scratch] 65. Detailed explanation of Python regular expression modifiers and their applications
[Learn python from scratch] 64. The re.compile method in Python regular expressions Detailed explanation of usage
[Learn python from scratch] 63. Introduction to the re.Match class and its attributes and methods in regular expressions
[Learn python from scratch] 62. Python regular expressions: a powerful string matching tool
[Learn python from scratch] 61. Detailed explanation and application examples of property attributes in Python
[Learn python from scratch] 60. Exploration generator: a flexible tool for iteration
[Learn python from scratch] 59. Iterator: An efficient tool for optimizing data traversal
[Learn python from scratch] 58. Custom exceptions in Python and methods of raising exceptions
[Learn python from scratch] 57. Use the with keyword in Python to correctly close resources
[Learn python from scratch] 56. The importance and application of exception handling in programming
[Learn python from scratch] 55. Serialization and sum in Python Deserialization, application of JSON and pickle modules
[Learn python from scratch] 54. Writing data in memory
[Learn python from scratch] 53. CSV files and Python’s CSV module
[Learn python from scratch] 52. Reading and writing files - Python file operation guide
[Learn python from scratch] 51. Opening and closing files and their applications in Python
[Learn python from scratch] 49. Object-related built-in functions in Python and their usage
[Learn python from scratch] 48 .Detailed explanation of inheritance and multiple inheritance in Python
[Learn python from scratch] 47. The concept and basic use of inheritance in object-oriented programming
[Learn python from scratch] 46. Analysis of __new__ and __init__ methods and singletons in Python Design Patterns
[Learn python from scratch] 45. Class methods and static methods in Python
[Learn python from scratch] 44. Private properties and methods in object-oriented programming
[Learn python from scratch] 43. Examples in Python object-oriented programming Properties and class attributes
[Learn python from scratch] 42. Built-in properties and methods in Python
[Learn python from scratch] 41. python magic method (2)
[Learn python from scratch] 40. python magic method (1)
[Learn python from scratch] 39. Basic object-oriented syntax and application examples
[Learn python from scratch] 38. How to use and import Python packages
[Learn python from scratch] 37. The use and precautions of Python custom modules
[Learn python from scratch] Learn python] 36. Methods and techniques of using pip for third-party package management in Python
[Learn python from scratch] 35. Common Python system modules and their usage
[Learn python from scratch] 34. Detailed explanation of the import and use of Python modules
[ Learn python from scratch] 33. The role of decorators (2)
[Learn python from scratch] 32. The role of decorators (1)
[Learn python from scratch] 31. In-depth understanding of higher-order functions and closures in Python
[From Learn python from scratch】30. In-depth understanding of recursive functions and anonymous functions
【learn python from scratch】29. "Detailed explanation of function parameters" - understand the different uses of Python function parameters
【learn python from scratch】28. Local variables and global variables in Python Variables
[Learn python from scratch] 27. The use of Python functions and nested calls
[Learn python from scratch] 25. Functions: a tool to improve the efficiency of code writing
[Learn python from scratch] 24. String operations and traversal methods in Python
[Learn python from scratch] 23. How to use sets (set) and common operations in Python
[Learn python from scratch] 22. Add, delete, modify, and query dictionary variables in Python
[Learn python from scratch] 21. Python tuples and dictionaries
[Learn python from scratch] 20. Python list operation skills and examples
[Learn python from scratch] 19. Applications of looping through lists and list nesting
[Learn python from scratch] 18. Detailed explanation of the basic operations of Python lists (1)
[From Learning python from scratch】 17. The format method of Python strings (2)
【Learning python from scratch】 16. The format method of Python strings (1)
【Learning python from scratch】 15. In-depth understanding of strings and character set encoding
【From Learning python from scratch】14. Common operations on Python strings (2)
【Learning python from scratch】13. Common operations on Python strings (1)
【Learning python from scratch】12. Python string operations and applications
【Learning python from scratch】 11. Python loop statements and control flow
[Learn python from scratch] 10. Detailed explanation of Python conditional statements and if nesting
[Learn python from scratch] 09. Conditional judgment statements in Python
[Learn python from scratch] 08. Python understands bit operations operator, operator priority
[Learn python from scratch] 07. Detailed explanation of Python operators: assignment, comparison and logical operators
[Learn python from scratch] 06. Use arithmetic operators in Python for calculations and string concatenation
[Learn from scratch] python ] 05. Output and input in Python
[Learn python from scratch] 04. Basics of Python programming: variables, data types and identifiers
[Learn python from scratch] 03. Python interactive programming and detailed explanation of comments
[Learn python from scratch] 02. Introduction to development tools
[Learn python from scratch] 01. Install and configure python

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/132753067
Recommended