Shell_05 variable name and meaning

Source: Internet
Author: User

Shell_05 variable name, meaning variable name meaning $ n the nth domain of the current record, number of ARGC command line parameters for all fields recorded by FS $0 in the ARGIND command line (start with 0) array of ARGV command line parameters CONVFMT digital conversion format ENVIRON environment variable Association array ERRNO last system error description FIELDWIDTHS field width list, use the Space key to separate the number of records in the FNR browsing file of the current FILENAME file. The FS Field Delimiter is the default value: the Space key IGNORECASE Boolean variable. If it is true, match the number of domains in the current record of NF with case-insensitive. NR current record count OFMT number output format OFS output domain separator. Default Value: Space key ORS output record separator, the default value is the line break RLENGTH, which is the string length RS record delimiter matched by the match function. The default value is the Space key RSTART, which is the SUBSEP array subscript delimiter at the 1st position of the string matched by the match function. The default value is \ 034 netstat-ntulp | grep-v "Active" | grep-v "Proto" | sed's //:/G' | sed "s /\. /:/g "| sed" s/fe80 \: // g "| awk-F ': | + ''{print $1" \ t "$8" \ t "$13" \ t "$15" \ t "$16} '| head-30 awk overview: awk is a programming language, which is equivalent to bash at the software level and is mainly used to process text and data in linux/unix. Data can come from standard input, one or more files, or the output of other commands. It supports advanced functions such as user-defined functions and dynamic regular expressions, and is a powerful programming tool in linux/unix. It is used in the command line, but more is used as a script. Awk processes text and data in this way. It scans files row by row. By default, it searches for matching rows in a specific mode from the first row to the last row, and perform the operations you want on these rows. If no processing action is specified, the matched rows are displayed to the standard output (screen). If no mode is specified, all the rows specified by the operation are processed. Awk represents the first letter of the last name of the author. The authors are three people, Alfred Aho, Brian Kernighan, and Peter Weinberger. Gawk is the GNU version of awk. It provides Bell Labs and GNU extensions. The awk introduced below is based on GNU gawk. in linux, awk has been linked to gawk, so we will introduce it all below. Awk commands can be used in two ways: 1) command mode awk [options] 'commands' file (s) command part:/range description/{awk command statement 1; awk command statement 2 ;} description of the range part can be BEGIN, END, logical expression, or empty awk command statements. Use semicolons to reference shell variables. Use double quotation marks to cause option part.-F defines the field delimiter. 2) script Mode awk [options]-f scriptfile file (s) features: the awk script is the LIST Command of the awk command. The command must start with the # sign with a semicolon (;) to comment on the line field and separate the awk. use $1, $2, $3... $ n indicates the different fields of each column separated by an interval symbol in files. $0 indicates that the awk of the row itself splits each line into separate fields using a space character as the delimiter by default., you can also use the awk built-in variable FS to define the interval symbol awk use the-F parameter in option to define the default interval symbol NF variable to indicate the number of fields (number of columns) of the current record $ NF last One column $ (NF-1) penultimate column FNR/NR row number FILENAME file name "\ t" tab RS Line Break "" print string # awk 'begin {FS = ": "} {print $1} '/etc/passwd $ head-5/etc/passwd> passwd $ awk-F':'' {print FILENAME, FNR, NF, $1, $2, $3, $4, $5, $6, $7, "\ t" $0 }'. /passwd. /passwd 1 7 root x 0 root/bin/bash root: x: 0: 0: root:/bin/bash. /passwd 2 7 bin x 1 bin/sbin/nologin bin: x: 1: 1: bin:/sbin/nologin. /passwd 3 7 daemon x 2 2 daemon/sbi N/sbin/nologin daemon: x: 2: 2: daemon:/sbin/nologin. /passwd 4 7 adm x 3 4 adm/var/adm/sbin/nologin adm: x: 3: 4: adm:/var/adm:/sbin/nologin. /passwd 5 7 lp x 4 7 lp/var/spool/lpd/sbin/nologin lp: x: 4: 7: lp:/var/spool/lpd: /sbin/nologin print all rows $ cat passwd $ awk-F': ''{print $0} 'passwd $ awk-F ': ''{print} 'passwd takes the first and second columns to the last, $ head-1 passwd | awk-F':'' {print $ NF, $(NF-1 )} '/bin/bash/root line break (one line is processed by default Wrap only after) $ head-1 passwd | awk-F': ''{print $ nf rs $(NF-1 )} '/bin/bash/root $ head-1 passwd | awk' BEGIN {FS = ":"} {print $ nf rs $(NF-1 )} 'specify multiple separators at a time $ awk-F': |/'{print NF}' passwd $ awk-F '[: /] ''{print NF} 'passwd $ ifconfig eth0 | grep Bcast | awk-F ': | + ''{print $4} '$ ifconfig eth0 | grep Bcast | awk-F" "' {print $2} '| awk-F ": "'{print $2}' address: 1) BEGIN: indicates to execute END before the program starts: indicates to execute the operation process after all files are processed: #/bin/awk-fBEG IN {}-- pre-read (read target file) {}-- END of row processing {}-- Print Title and END information after read processing $ awk-F ': ''in in {print "user \ tpasswd \ thome" RS "--------------------" };{ print $1 "\ t" $2 "\ t" $(NF-1 )}; END {print "<----------- END ---------->"} 'passwd user passwd home -------------------- root x/rootbin x/bindaemon x/sbinadm x/var/admlp x/var/spool/lpd <----------- END ----------> 2) regular Expression $ awk '/root/{print $0}'/etc/passwd -- use common characters to locate root: X: 0: 0: root:/bin/bashoperator: x: 11: 0: operator:/root:/sbin/nologin $ awk '$0 ~ /^ Root/{print $0} '/etc/passwd -- use a regular expression to locate root: x: 0: 0: root:/root: /bin/bash $ awk '/^ [rR] oot | ^ [bB] in/{print $0}'/etc/passwdroot: x: 0: 0: root: /root:/bin/bashbin: x: 1: 1: bin:/sbin/nologin # awk-F ': ''/^ [rR] oot | ^ [bB] in/{print $1} 'passwd uses a regular expression to precisely locate $ awk-F ': ''' $2 = "" {print $0} '/etc/passwd $ awk-F ': ''' $2 = "" {print $0} '/etc/shadow -- check whether there is a blank password in the user $ awk-F': ''$7 ~ /Bash $/{print $0} '/etc/passwd $ awk-F ': ''nr> = 5 & NR <= 10 {print $0} '/etc/passwd $ awk'/^ root /, /^ uucp/{print $0} '/etc/passwd 3) logical expression example: NR> 40 example: if ($2> 50) {print $3} logical expression: = (equal ),! = (Not equal to),> (greater than), <(less than),> = (greater than or equal to), <= (less than or equal )~ (Matched) and !~ (Does not match )! (Not), & (and), | (OR), and brackets () awk-F: 'nr <10 & NR> 3 {print $0} '/etc/passwd -- with awk-F: 'nr = 10 | NR = 3 {print NR, $0} '/etc/passwd -- or awk-F :'! (NR <40) {print NR, $1} '/etc/passwd -- reverse awk-F: '$3> = 500 & $3 <= 60000 {print $3, $1}'/etc/passwd -- print normal user awk-F: 'nr % 2 = 0 {print NR, $0} '/etc/passwd -- take even awk-F: 'nr % 2! = 0 {print NR, $0} '/etc/passwd -- print odd line awk-F: 'nr % 2 = 1 {print NR, $0} '/etc/passwdawk-F ":" 'In in {print "user_UID \ tusername \ t" RS "-------------------"}; ($3> = 500 & $3 <= 60000) {print $3 "\ t", "\ t" $1 }; END {print "--------------------"} '/etc/passwd awk process control if for while if (expr1) actionif (expr1) action2; else aciton2if (expr1) action1; else if (expr2); else # awk-F: '{if ($3> 500) print $1, $3, "normal user"} '/etc/passwd # awk-F:' {if ($3> 500) print $1, $3, "normal user "; else print $1, $3, "not a common user"} '/etc/passwd # awk-F:' {if ($3 = 0) print $1, $3, "Administrator"; else if ($3 <500) print $1, $3, "system user"; else print $1, $3, "normal user"} '/etc/passwd for # awk' BEGIN {for (I = 0; I <= 10; I ++) print I} 'while # awk' BEGIN {I = 0; while (I <= 5) {print I; I ++} '# awk' BEGIN {I = 0; while (I <= 5) {print "service", I, "start"; I ++} '# loop control: break -- interrupt loop continue when conditions are met -- Skip loop when conditions are met # awk 'in in {I = 0; while (I <= 5) {I ++; if (I = 3) continue; print I }}' # awk 'BEGIN {I = 0; while (I <= 5) {I ++; if (I = 3) break; print I} Use netstat-ntl to intercept all open port numbers netstat-ntl | grep-v Active | grep-v Proto | awk '{print $4}' | awk-F: '{print $ NF}' netstat-ntlup | grep-Ev "Active | Proto" | awk '{print $4}' | awk-F: '{print $ NF }'

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.