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 ENV... 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, the number of domains in the current record of NF is case-insensitive. NR current record number. OFMT number output format: OFS output domain. Delimiter. the default delimiter is the space key ORS output record delimiter. the default delimiter is the line break RLENGTH, which is the string length RS record delimiter matched by the match function, by default, the space key RSTART is the SUBSEP array subscript separator, which is 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.