Grep,sed,awk personal Summary
The regular expression ifconfig | sed-n '2p' | sed 's.roominetUniGOG' | sed's regular netmask. Regular extension after / # can theoretically be replaced by any special character # sed-r can be followed by extension regular extension + (. *) ifconfig | sed-n 2p | sed-r's # ^. * inet (. *) Broast.*$#\ 1normalg'\ 1 represents the regular middle The first GROUP in (. *) is the content ifconfig in (. *) ifconfig | sed-nr '2s# ^. * inet (. *) net.*$#\ 1 synthesize a line ifconfig | awk' NR==2 {print $2}'# take IP address awk default separator is the most convenient ifconfig ens33 for IP with spaces | grep-o "inet [0-9.] *" | grep-o "[0-9.] *" # take IPifconfig ens33 | sed-nr'2s # ^. * inet ([0-9]. *) netmask.*$#\ 1#gp'cat oldboy.txt | sed-r's # ^. * inet (. *) netmask (. *) broadcast (. *) $^ C1\ 2\ 3 # g 'sed-r's # (. *): (. *): (. *) $#\ 7\ 6\ 5\ 3\ 2\ 1 # the maximum number of sed references is 9 after changing positions to references. It is more convenient to use awk to delete sed-n'/ ^ $/ d'# blank lines / / write the string sed'1 here & here & on behalf of C C it can also be the regular expression ls | sed's # (^. *) #mv\ 1.jpgpromog' | bash sed '1~2p's # an i d odd line sed' 2~2p's # an i d even line sed's # ^ # head#g' # add sed's multiple lines operation sed'2a with sed's # ^ # test#g' # at the beginning and testsed's multiple lines operation at the end of testsed Str' '1century 2a recorder str' 1rec 10i recorder str' /' 1recorder 2d '5pm 10d' / '1quote 3p' '1recorder 3p' 1p'1 must have corresponding line in an i d, empty file will make an error In other words, empty files cannot be directly added to sed'/ new/d' # with sed to delete lines containing new. In the sed command-n p in n p sed-n p basically appears in pairs awk-F ":"'{print $1 ":" $2 ":" $3 ":" $4 ":" $5 ":" $6 ":" $7 "-" $1} 'passwd # here is the full-text operation awk-F "5. : 5 | 28 "'NR==5 {print $2}' # 5:5 or 28 as a delimiter two strings are best used | even if a single character is used | otherwise the string causes ambiguity ll | awk'{if ($2 > 5) print $0}'$0 indicates the entire line sed-I's changing the pp in the 1.txt file to dd effective immediately-I means writing directly to the file
# in LINUX, all text processing is done by reading one line (into memory), processing one line output and ending one line in a loop
Use "" for regular expression strings in case of problems
^. * begins with any character. * $ends with any character. ^ word begins with word. Word$ ends with word. [^ word] inverted in parentheses. Represents only one character "Yes character matches all except blank lines" spaces and blank lines are different\ escape * repeat the previous 0 or more characters. * all [abc] matches any character [^ abc] in the set [^ character] matches any character in the set except abc [0-9] [AMuz] [AMuz] a\ {n M\} repeat an at least n times to at most m times # # a\ {NMagol m\} this form must be quoted with "" and there are no spaces on both sides, otherwise an error a\ n,\} a\ {will be reported. M\} a\ {n\} repeat egrep sed-r n times without using\ escape # # to understand the extended regular expression grep-E egrep+ one or more (* is 0 or more)? 0 or a preceding character | indicates that multiple strings egrep "sshd | systemd" () are filtered at the same time and then reference reference (. *)\ 1grep-n-I is case-insensitive-o is only displayed The matching content does not output the whole line of find / test-type f-name "* .sh" | xargs sed-I's uploading newuplog`! The exclamation mark can be reversed-an and-o or can also be written at the same time sed-I's roomoldwords newchangg'. Sh#awkNR $0 full row $1 $2$ NF the last column NF is the full row column $(NF-1) the penultimate line # awk principle one line is a record # RS indicates that the end of a record FS indicates that the separation of an area $NF is the last area ifconfig | awk 'BEGIN {RS= ":"}' {print " $1}'to: instead of carriage return as the newline character # regular condition (NR==2) range (NR==2 NR==5) 2 to "$1" / regular start /, $3 "/ regular end / awk-F" [:] + |\ t + "'{print $2} 'grade with one or more: (spaces or colons) or 1 or more tab tabs as delimiters # BEGIN module END module seq 1 100 | awk' {print a}'1} 'END {print a}' added to 100cat passtemp | awk'{sub (/ x / /) "ppp")}'{print $0} 'awk replace awk' $1~/lisi/ {print $0} 'grade grade file matches $1 line including lisi and prints out line awk' $419 / (5 | 3) $/ {print $0} 'grade match 5 or 3 ends awk' $1cm / ^ [l | W] / {print $0} 'grade match l or W begins with [] and () is strongly recommended for regular matching. Awk-F "\ t"'$3percent / ^ 9 / {print $0} 'grade# does not contain:! Is not included in the awk to use! In awk, there are three functions that can be replaced: sub gsub gensubsub (r, s [, t]) r / find who / s "replace with what" [] replace that part of awk'$1~/zhan/ {gsub (/ zhang3/, "ccccc", $1); print $0} 'grade## attention / zhang3/ "ccccc" and between multiple commands; semicolon