Text Processing:
Cut echo sort Uniq WC tr
Text view:
Cat tac more less tail head
Text Processing
# cut Text output
[[Email protected] ~]# cut --help Usage: cut [option]... [file] ... print selected parts of lines from each file to standard Output. mandatory arguments to long options are mandatory for short options too. -b, --bytes= List Select only those bytes specified -c, --characters= list Select only the specified characters -d, --delimiter= the delimiter Use the specified delimiter instead of a tab as the area demarcation -f, --fields=list select only these fields; also print any line that contains no delimiter character, unless The -s option is specified
-d Specifies the field delimiter, which by default is a space
-F 1,3 Specifies that 1, 3 fields are displayed
-F 1-3 Specifies that 1-3 fields are displayed
Example: #cut-D:-f1/etc/passwd
# Echo, write parameters to standard output
[[email protected] ~]# help echoecho: echo [-nee] [parameter ...] writes parameters to standard output. Show ARG parameters on standard output followed by a line break. Options: -n do not append line breaks -e enable the following backslash escape interpretations -E Explicitly suppresses interpretation of backslash escapes ' echo ' escapes the following backslash characters: \b BACKSPACE \e Escape characters \f Format offers \n NewLine \r Enter \t Horizontal Tab \v Portrait tab
Example: #echo-E "This is 2017. \ n This is 23 "
Example:Echo- E "\033[1;31;41mhello\033[0m " color Display,\033RepresentativeCtrlcharacters,1represents the font format, torepresents the background color, Arepresents the foreground color tombegins with the\033[0mEnd
#sort Text Sorting
[[Email protected] ~]# sort --help Usage: sort [option]... [file] ... Or: sort [option]... --files0-from=fwrite sorted concatenation of all file (s) to standard output. mandatory arguments to long options are mandatory for short Options too. Sorting Options: -f, --ignore-case Ignore letter Case -h, --human-numeric-sort Use legibility numbers (ex: 2k 1g) -n, --numeric-sort comparison by string values -R, --random-sort Sort by random hash --random-source= File get random bytes from the specified file -r, --reverse reverse output sort result --sort= word according to WORD Sort the specified format: General Digital-G, high readability-H, month-m, digital-n, Random-R, version-v -v, -- version-sort the natural version sort within the text -k , --key=keydef Specifying display fields -m, --merge merge already sorted files; do not sort -u, --unique with-C, strict verification of the sort; not with-C, output only once sorting results -o, --output= file Writing results to a file rather than standard output -s, --stable disable last-resort comparison to stabilize comparison algorithm -s, --buffer-size= size Specify the main memory cache size -t, --field-separator= separators Converts with a specified delimiter instead of a non-whitespace to a space
Example: #sort-T:-K 3-n/etc/passwd, put the 3rd field in the/etc/passwd file, sort the display by a string
#uniq Display
[[Email protected] ~]# uniq --help Usage: uniq [option]... [file]filter adjacent matching lines from input (or standard input),writing to output ( Or standard output). with no options, matching lines are merged to the first Occurrence. mandatory arguments to long options are mandatory for short options too. -c, --count Displays the number of rows in the text -d, --repeated shows duplicate rows -D, --all-repeated[=METHOD] Show all duplicate rows groups can be delimited with an empty line method={none (default),prepend,separate} -w, --check-chars=n does not control the contents of the n characters after each line
# WC display lines, words, bytes
[Email protected] ~]# WC--help usage: WC [option] ... [File] ... Or: WC [options] ...--files0-from=f-c,--bytes print the byte counts, shows the number of bytes-M,--chars print the Charac ter counts-l,--lines print the newline counts-l,--max-line-length shows the longest line length-W,--words Show Word Count
Example: #wc-L/ETC/PASSWD, showing the number of rows in/etc/passwd
# tr convert or delete characters
[[Email protected] ~]# tr --help Usage: tr [option]... set1 [set2] Replace, reduce, and/or delete characters from standard input , and writes the results to standard output. -d, --delete Delete matches set1 content, do not replace -s, --squeeze-repeats if match SET1 characters in the input sequence exist in continuous Repeat, will be uniformly shrunk to one character length at the time of substitution -t, --truncate-set1 set1 The length of the first and set2 equal --help Display this help message and exit --version display version information and exit [:alnum:] All the letters and numbers  &NBSP [:alpha:] all the letters [:blank:] all white space characters in horizontal order [:cntrl:] all control characters [:d igit:] All numbers [:graph:] all printable characters, not including spaces [:lower:] All lowercase letters [:p rint:] all printable characters, including spaces [:p unct:] All punctuation characters [:space:] all white-space characters that are arranged horizontally or vertically [ :upper:] All capital letters [:xdigit:] all hexadecimal numbers [= character =] All characters equal to the specified character
Example: #tr ab AB </etc/passwd, replace a with a in the/etc/passwd file, B and B
Text view:
#cat Link and display
[[Email protected] ~]# ^c[[email protected] ~]# cat --help Usage: cat [options] .... [file] ... Output the [file] or standard input combination to the standard output. -A, --show-all equals-vet -b, --number-nonblank number of non-null output lines -e equals-ve -e, --show-ends displays "$" at the end of each line -n, --number Numbering all lines of output -s, --squeeze-blank not outputting multiple lines of blank lines -t and-vt equivalent -t, --show-tabs to display the ^i character as the Jump cell
Reverse display of #tac (cat's reverse)
#more split screen display, turn back screen, do not support forward
#less split screen display, support forward and backward flip screen
#head: View Top N rows
-N Displays rows
#tail: Show the following n rows
-N Displays the last n rows
-F View the end of the file and wait for the new content appended to this file to be displayed
[[email protected] ~]# more /etc/passwdroot:x:0:0:root:/root:/bin/bash.../null:/sbin/ nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:privilege-separated ssh:/var/empty/ Sshd:/sbin/nologin[[email protected] ~]# less /etc/passwdroot:x:0:0:root:/root:/bin/bash ... daemon:/dev/null:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74: Privilege-separated ssh:/var/empty/sshd:/sbin/nologin[[email protected] ~]# head -1 /etc/passwd #显示第一行root: x:0:0:root:/root:/bin/bash[[email protected] ~]# tail -1 /etc/passwd #显示最后一行sshd: X:74:74:privilege-separated ssh :/var/empty/sshd:/sbin/nologin[[email protected] ~]# cat /etc/passwdroot:x:0:0:root:/root :/bin/bash...daemon:/dev/null:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74: Privilege-separated ssh:/var/empty/sshd:/sbin/nologin[[email protected] ~]# tac /etc/passwdsshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologin...root:x:0:0:root:/root:/ bin/bash[[email protected] ~]#
Crtl + C abort symbol, force end of text or command not displayed
This article is from the "Wish_" blog, be sure to keep this source http://itwish.blog.51cto.com/11439802/1961986
Linux Learning Notes-text management commands and related options