Linux text handling command
Sort command
The function of the sort command is to sort the rows in the file. The sort command has many very useful options that are originally used to perform various sorted file contents for the database format. In fact, the sort command can be considered a very powerful data management tool to manage content similar to database records.
The sort command will be sorted by the contents of the file. If the first character of the two rows is the same, the command will continue to compare the next character of these two lines, if it is also the same, will continue to compare.
grammar:
Sort [option] file
Note: The sort command sorts all the rows in the specified file and display the results on the standard output. If you do not specify an input file or use "-", the sorting content is from standard input.
Sort Sort is done according to one or more keywords extracted from the input row. Sorting keywords define the smallest character sequence used to sort. By default, you are sorted in the ASCII character sequence in a single behavior keyword.
Change the options for default settings Main:
- M If a given file has been raised, the merge file.
- C checks if a given file is ranked, if they do not have a sequence, print an error message and exit in status value 1.
- u On only one line of rows, only the same line is left.
- O Output file writes the sorting output to the output file instead of the standard output, if the output file is one of the input files, Sort first writes the contents of the file into a temporary file, then sort and write the output result.
Change the options for default sorting rules Main:
- d Sort by dictionary, only letters, numbers, spaces, and tabs are meaningful when compared.
- f Treat your lowercase letters with uppercase letters.
- i ignores non-print characters.
- M as a month comparison: "jan" <"feb"
- r Sampling results in reverse sequence.
POSL - POS2 Specifies one or several fields as sorting keywords, field position starts from POSL, until POS2 (including POSL, does not include POS2). If POS2 is not specified, the keyword is from POSL to the end. The position of the field and characters starts with 0.
- b Look for a blank (spaces and tab) that ignores the predecessor (spaces and tabs) when sorting the keywords in each row.
- T separator Specifies the character Separator as a field separator.
UNIQ command
The file may have a repeated row in its output file after processing. For example, after using the CAT command, you can use the sort command to sort, you may have a repeated line. At this time, you can use the UNIQ command to remove these repeat lines from the output file, leaving only the only sample of each record.
grammar:
UNIQ [option] file
Description: This command reads the input file and compares the adjacent rows. Under normal circumstances, more repeated rows will be deleted in the second and later, and the line comparison is based on the sort sequence of the set character set. The result of this command is written to the output file. Enter files and output files must be different. If you enter a file with "-", you are read from the standard input.
The commands each option is as follows:
- C The display output in each line, the number of times the Bank appears in the file. It can replace the U and-D option.
- D shows only the repeated line.
- u Only lines do not repeat in the file.
- n The front n field is ignored with the blank before each field. A field is a non-air, non-made string string, separated from each other (fields from 0).
n The n characters before it is ignored, and the previous character is skipped (the character is numbered from 0).
- f N is the same as - n, where n is the number of fields.
- S n is the same as n, where n is the number of characters.