Shell_03 advanced operations

Source: Internet
Author: User
Tags egrep
Shell_03 advanced operations on advanced operations text: wc-c-l-wdiff -- view different places between two files and compare the two files. -B ignore space caused by different-I ignore case-B ignore Insert space caused by changes sort -- sort-r reverse-n sort by number-u remove... shell_03 advanced operations on advanced operations text: wc-c-l-w diff -- view different places between two files and compare the two files. -B ignore space-caused differences-I ignore case-B ignore changes caused by space insertion sort -- sort-r reverse-n sort by number-u remove duplicate rows in the result-t the column-o with the specified separator-k indicates that the output is written to the specified file, it is equivalent to redirecting the output to the specified file-c test file whether the file has been sorted-m merge two sorted files uniq -- remove duplicate rows-c count the number of duplicated rows-I ignore case-d only show duplicate rows-u only show no duplicate records cut -- removes the serial number of the specified character segment between rows-d specify the separator-f specify the column-c character c1-100 join command used to connect two files, the connection operation selects records with the same domain in the two files and places all these records in one row (including all the domains from the two files) -a1 or-a2: in addition to displaying the results of connecting with a common domain,-a1 indicates that there are no records of the common domain in the 1st files, -a2 indicates that none of the 2nd files are displayed. When a record with a common domain-I compares the domain content, ignore case sensitivity differences-o settings result display format-t changes the domain separator-v1 or-v2 is similar to the-a option, however, do not display the result paste-merge two files using a common domain.-d the default domain separator is a space or a Tab key, set the new domain separator-s to paste each file into a line-read data from standard input # ls | paste-d ""--split to cut large files small file, the split command can cut the file according to the number of lines and the number of bytes, and automatically add the number-or-l to the output of multiple small files. These two options are equivalent, it is used to specify the number of lines cut into small files-B specifies the bytes cut into small files-C is similar to the-B option, however, maintain the integrity of each line during cutting # split-l50/etc/passwd # split-b1000/etc/passwd sb tr -- replace, only file streams with redirection input can be accepted-delete all files except a specified string-s. Only one # tr-s '[\ n]' <AREACODE. db compresses repeated line breaks into a BEIJING: 86010 HONGKONG: 852 SHANGHAI: 86021 TORONTO: 001416 # tr-d A-Z <AREACODE. db deletes all uppercase characters # tr-d "[\ n]" <AREACODE. db deletes all linefeeds \ B return characters \ r return keys \ t tab keys # cat testWooooomennnnTTTTheyyyy # tr-s "[a-z], [A-Z] "<test compresses all repeated characters into one character # tr-s" [a-z] "" [A-Z] "<test converts all lowercase letters to uppercase # tr" [o * 5] "" @ "<test changes the o character of the file to the @ character # tr-d 'a-z' for five consecutive times <AREACODE. db | grep-v ^ $ | Tee dbn. out &>/dev/null & tr-D': '<dbn. out # cut-d:-f2 AREACODE. db | grep-v '^ $ 'Tee -- bidirectional redirection-a append # who | tee who. out regular expression (regex) -- used to precisely match the first regular expression in text: (1 ).: represents any single character, except the line break (2) *: The leading character appears 0 or multiple times (3 ). *: any length of characters (4) ^: Starting line (5) $: End of line (6) ^ $: empty line (7) [abc] in characters or relationships (8) [a-z] [A-Z] [0-9] (9) [^ abc] take Non (10) ^ [abc] rows starting with a, B, or c (11) ^ [^ abc] starting with not a, not B, or not c (12) \ <: get the word header (13) \>: get the end of the word-regular expression of the extension class (14) +: 1 or multiple times (15 )?: 0 times or 1 time (16) \ <\> exact match symbol (17) \ {n \} match the previous character appears n times (18) \ {n, \} match the first character to appear at least n times (19) \ {n, m \} match the first character to appear n times and m times between the second type of regular expression (POSIX standard ): [[: digit:]: number [[: lower:]: lower-case letter [[: upper:]: upper-case letter [: space:]: space [[: alnum:]: Regular expression tools (software) supported by letters and numbers: grep/egrep find locate sed awk vim grep 'regex' file -- write the regular expression in single quotes, prevent shell from interpreting the regular expression grep-E 'regex' file -- to match the extended regular expression, add the-E option egrep = grep-E # find/-regex' in grep '. *\. iso $ '# find/-regex' ^ \/ Var. *\. iso $ 'locate-r # locate-R' ^ \/var. *\. iso $ 'SED-n'/^ root/p'/etc/passwd awk '/^ root/{print $0}'/etc/passwd vim/^ root/nologin $: % s/^ root/ROOT/g grep o: print only the matched characters n: Show the row number v: reverse l: match successful, print file c: count the number of matched characters, but count the number of rows instead of the number of matched characters. A: match the number of rows. B: match the first few rows. C: match the first few rows, for example,-C 2 and-2i: ignore case-insensitive q: Silent execution. Generally, when testing, retrieve the return value and use r/R: to search all files in a directory -- color: use special colors to mark matched keywords H: list file paths matching keywords egrep: Extended regular search egrep = grep-E # cat grep.txt gglegoglego The operation of oglegoooglegaglegaaglegaaagleabcgef abcdef is as follows: grep 'G. G' grep.txt -- grep 'g * g' grep.txt -- can be any character in the middle of two g letters. Equivalent to grep g grep.txt grep 'go * g' grep.txt -- grep 'G can be used as long as there are zero o or multiple o in the middle of two g letters. * g'grep.txt -- grep 'go. * g'grep.txt -- as long as the go and g letters have zero or any character in the middle, you can/etc/passwdgrep ^... t/etc/passwd -- find the line grep o with the fourth character t in each line ..... $/etc/passwd -- find the line grep s with the sixth to Last character o in each line .. n/etc/passwd -- query the rows with s and n characters in each line and grep x: 4 in the middle: /etc/passwd -- search for rows with uid 4 (only grep and regular expressions are used, and cut or awk is not used) grep. *:.: 4 :. *:. *:. *:. */etc/passwd -- find 4 In uid The row grep. *:. :. * 4. *:. *:. *:. *:. */etc/passwd -- find the 4 rows grep in uid. *:. *:. *:. *::. *:. */etc/passwd -- find the grep-v comment column in/etc/passwd. *:. *:. *:. *::. *:. */etc/passwd -- find the grep of the comment column not empty in/etc/passwd. *:. *:. *:. *:.. *:. *:. */etc/passwdgrep. *:[! X]. *:. *:. *:. *:. *:. *:. *:. */etc/shadow -- find the grep root/etc/passwd user who cannot log on normally with a password on the logon interface -- filter the keyword grep '^ root'/etc/passwd -- start with root line grep 'bash $ '/etc/passwd -- line grep ending with bash' ^ $ '/etc/passwd -- find empty line grep' ^ [ru] '/etc/passwd -- r or ugrep '[0-9]'/etc/passwd -- find the number grep '^ [^ abc]'/etc/passwd -- reverse, grep '\ '/Etc/passwd -- \ <get the word header, \> get the end of the word grep-E' ^ root | ^ zhang '/etc/passwd -- color -- expand the regular expression, -E: Match grep-n root/etc/passwd starting with root or zhang -- grep-oE with row number filtering ([0-9 }\.) {3} [-- 9] {1, 3}) '/var/log/secure -- filter the IP address grep [[: digit:]/etc/passwd grep [[: lower:]/etc/passwd grep [[: upper:]/etc/passwd grep [[: space:]/etc/passwd grep [[: alnum:] /etc/passwd find dir1 dir2... [options]... find/etc/-maxdepth 1: -- maximum depth of find/etc/-maxdepth 1-type d | f | s | B | c | l: -- maximum depth + file type find/etc/-type f-name "passwd"-ls: -- find/etc/-type f-user user01-group group01: -- search for find/etc/-type f-perm 644 by user and group: -- search for find/etc/-type f-perm + 640 by permission: -- + indicates the link "find/etc/-type f-perm-640: ---" indicates that the table with the link "0" indicates that the "+-" table is empty, find/bin-type f-perm + 4000-ls: -- find the file with suid permission. -type f-size + 5 M-a-size-8 M: -- find files larger than 5 M and smaller than 8 M. -type f-size-5 M-o-size + 8 M: -- find files smaller than 5 M and larger than 8 M. -type f-size 1 M-OK rm {}\;: -- delete find in interactive mode. -type f-size 1 M-exec rm {}\;: -- delete regular expressions in non-interactive mode: # cd/etc # find. -maxdepth 1-regex '\. /. * d $ '# find. -maxdepth 1-regex '\. /h. * d $ '# find. -maxdepth 1-regex '\. /. * [0-9]. * '-- find the file name in the/etc directory that contains numbers-type-name-size-perm-user-group-maxdepth N-mtime: -exec-OK-o-a-not-regex
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.