Search based on keyword
Command grep is used to search for text based on keywords
$ grep ' Shuangde '/etc/passwd
$ find/-user Shuangde | grep video
-I ignores case when searching
-N Displays the number of rows in which the result
-V output lines with no keywords
-ax the specified number of rows after the result is included in the output
-BX the specified number of rows before the result is included in the output
Working with text based on columns
Command cut is used to process text content based on columns
$ cut-d:-F 1/etc/passwd separated by a colon and displays the first column of the passwd file (if multiple columns are displayed:-F 1,2,3)
$ grep shuangde/etc/passwd | Cut-d:-F3
-d Specifies the Separator (tab is the default)
-f Specifies the output column number
-C segmentation based on character
$ cut-c2-6/etc/passwd
Display 2nd to 6th character
Text statistics
Command WC (Word count) to count text information
$ WC file output line number, Word number, number of bytes
-L (lines): Only count rows
-W (words): count only words
-C (bytes): Only count bytes
-M (chars): only count characters
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/
Text sorting
Sort command: To sort the line contents of text (English and numeric only)
$ sort filename
-R Reverse Order
-N sort based on numbers
-F ignores case
-U Delete Duplicate rows
-T C use C as a separator to sort columns
-K x Specifies the sort based on that column when the sort based on the specified character is divided into columns
Delete duplicate rows
$ sort-u can delete duplicate rows
$ uniq to delete adjacent duplicate rows
Text comparisons
diff Command: Compare differences between two text files in one row
$ diff file1 File2
-I ignores case
-B ignores changes in the number of spaces
-U Displays comparison information uniformly (typically used to generate patch files)
$ diff-u file1 file2 > Final.patch
Spell check
Aspell command: Show check spelling in English
$ Aspell Check file checks the spelling of the word in the filename and can be corrected
$ Aspell list file to put the wrong words inside the files and show them
Working with text content
TR command: Change or delete text content
Delete a keyword
$ Tr-d ' TMD ' < filename erase t,m,d three letters
Convert case
$ Tr ' A-Z ' ' A-Z ' < filename
Search Replace
SED command: To search for and replace text (stream editor for filtering and transforming text.)
$ sed ' s/linux/unix/g ' file
$ sed ' 1,50s/linux/unix/g ' file
$ Sed-e ' s/linux/unix/g '-e ' s/hehe/haha/g ' file can specify multiple matching modes
$ sed-f Sededit File