当前位置: 首页 > news >正文

大学生服务性网站建设方案/怎么做一个网页

大学生服务性网站建设方案,怎么做一个网页,wordpress 邮件代发,湖南做网站 尖端磐石网络Linux三剑客&常用命令&shell常识 Linux三剑客grep - print lines matching a patternsed - stream editor for filtering and transforming textawkman awk Linux常用命令dd命令ssh命令tar命令curl命令top命令tr命令xargs命令sort命令du/df/free命令 shell 知识functio…

Linux三剑客&常用命令&shell常识

  • Linux三剑客
    • grep - print lines matching a pattern
    • sed - stream editor for filtering and transforming text
    • awk
      • man awk
  • Linux常用命令
    • dd命令
    • ssh命令
    • tar命令
    • curl命令
    • top命令
    • tr命令
    • xargs命令
    • sort命令
    • du/df/free命令
  • shell 知识
    • function的使用

Linux三剑客

grep - print lines matching a pattern

本人常用的grep参数:

  1. -i 忽略大小写 grep -i 'hello' **.txt **.c **.h
  2. -e 多条件过滤 grep -e 'hello' -e 'world' **.txt过滤出包含hello和world的行
  3. -E 支持扩展的正则表达 grep -E 'hello|world' **.txt=grep -e 'hello' -e 'world' **.txt
  4. -v 选中不匹配的行(反选)grep -v 'hello' *.txt 选出没有hello的行
  5. -H 打印文件名
  6. -n 打印行号
sx@sx-virtual-machine:~$ grep -EnH 'DESCRIPTION|OPTIONS' awk_man.txt
awk_man.txt:10:DESCRIPTION
awk_man.txt:21:OPTIONS
sxhan@sxhan-virtual-machine:~$
  1. -A n 打印文本及其后n行
sx@sx-virtual-machine:~$ grep -EnH -A 2 'DESCRIPTION|OPTIONS' awk_man.txt
awk_man.txt:10:DESCRIPTION
awk_man.txt-11-       mawk is an interpreter for the AWK Programming Language.  The AWK language is useful for manipulation of data files, text retrieval and processing, and for prototyp‐
awk_man.txt-12-       ing and experimenting with algorithms.  mawk is a new awk meaning it implements the AWK language as defined in Aho, Kernighan and  Weinberger,  The  AWK  Programming
--
awk_man.txt:21:OPTIONS
awk_man.txt-22-       -F value       sets the field separator, FS, to value.
awk_man.txt-23-
sx@sx-virtual-machine:~$
  1. -B n 打印文本及其前n行
sx@sx-virtual-machine:~$ grep -EnH -B 2 'DESCRIPTION|OPTIONS' awk_man.txt
awk_man.txt-8-       mawk [-W option] [-F value] [-v var=value] [-f program-file] [--] [file ...]
awk_man.txt-9-
awk_man.txt:10:DESCRIPTION
--
awk_man.txt-19-       onymous with lines.  Each record is compared against each pattern and if it matches, the program text for {action} is executed.
awk_man.txt-20-
awk_man.txt:21:OPTIONS
sx@sx-virtual-machine:~$
  1. -c 统计输出的行数
  2. 其他用法见 grep --help or man grep 的输出内容
sx@sx-virtual-machine:~$ grep --help
用法: grep [选项]... PATTERN [FILE]...
Search for PATTERN in each FILE.
Example: grep -i 'hello world' menu.h main.cPattern selection and interpretation:-E, --extended-regexp     PATTERN is an extended regular expression-F, --fixed-strings       PATTERN is a set of newline-separated strings-G, --basic-regexp        PATTERN is a basic regular expression (default)-P, --perl-regexp         PATTERN is a Perl regular expression-e, --regexp=PATTERN      用 PATTERN 来进行匹配操作-f, --file=FILE           从 FILE 中取得 PATTERN-i, --ignore-case         忽略大小写-w, --word-regexp         强制 PATTERN 仅完全匹配字词-x, --line-regexp         强制 PATTERN 仅完全匹配一行-z, --null-data           一个 0 字节的数据行,但不是空行杂项:-s, --no-messages         不显示错误信息-v, --invert-match        选中不匹配的行-V, --version             显示版本信息并退出--help                显示此帮助并退出Output control:-m, --max-count=NUM       stop after NUM selected lines-b, --byte-offset         print the byte offset with output lines-n, --line-number         print line number with output lines--line-buffered       flush output on every line-H, --with-filename       print file name with output lines-h, --no-filename         suppress the file name prefix on output--label=LABEL         use LABEL as the standard input file name prefix-o, --only-matching       只显示匹配PATTERN 部分的行-q, --quiet, --silent     不显示所有常规输出--binary-files=TYPE   设定二进制文件的TYPE 类型;TYPE 可以是`binary', `text', 或`without-match'-a, --text                等同于 --binary-files=text-I                        等同于 --binary-files=without-match-d, --directories=ACTION  读取目录的方式;ACTION 可以是`read', `recurse',或`skip'-D, --devices=ACTION      读取设备、先入先出队列、套接字的方式;ACTION 可以是`read'或`skip'-r, --recursive           等同于--directories=recurse-R, --dereference-recursive       同上,但遍历所有符号链接--include=FILE_PATTERN  只查找匹配FILE_PATTERN 的文件--exclude=FILE_PATTERN  跳过匹配FILE_PATTERN 的文件和目录--exclude-from=FILE   跳过所有除FILE 以外的文件--exclude-dir=PATTERN  跳过所有匹配PATTERN 的目录。-L, --files-without-match  print only names of FILEs with no selected lines-l, --files-with-matches  print only names of FILEs with selected lines-c, --count               print only a count of selected lines per FILE-T, --initial-tab         make tabs line up (if needed)-Z, --null                print 0 byte after FILE name文件控制:-B, --before-context=NUM  打印文本及其前面NUM 行-A, --after-context=NUM   打印文本及其后面NUM 行-C, --context=NUM         打印NUM 行输出文本-NUM                      same as --context=NUM--color[=WHEN],--colour[=WHEN]       use markers to highlight the matching strings;WHEN is 'always', 'never', or 'auto'-U, --binary              do not strip CR characters at EOL (MSDOS/Windows)When FILE is '-', read standard input.  With no FILE, read '.' if
recursive, '-' otherwise.  With fewer than two FILEs, assume -h.
Exit status is 0 if any line is selected, 1 otherwise;
if any error occurs and -q is not given, the exit status is 2.

sed - stream editor for filtering and transforming text

常用参数:

  1. -i 对文件原地编辑 sed -i 's/old_str/new_str/g **.txt 将**.txt文件中所有的old_str替换成new_str;s表示替换操作,g表示全局替换

这也是前两天面试官问我的问题,我没回答上来。。。。。
前几年真的用过sed,但也是真的忘了。。。😢😶

Tips:其他的详细用法,以后有空再更新。。。

sx@sx-virtual-machine:~$ sed --help
用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...-n, --quiet, --silent取消自动打印模式空间-e 脚本, --expression=脚本添加“脚本”到程序的运行列表-f 脚本文件, --file=脚本文件添加“脚本文件”到程序的运行列表--follow-symlinks直接修改文件时跟随软链接-i[SUFFIX], --in-place[=SUFFIX]edit files in place (makes backup if SUFFIX supplied)-l N, --line-length=N指定“l”命令的换行期望长度--posix关闭所有 GNU 扩展-E, -r, --regexp-extendeduse extended regular expressions in the script(for portability use POSIX -E).-s, --separateconsider files as separate rather than as a single,continuous long stream.--sandboxoperate in sandbox mode.-u, --unbuffered从输入文件读取最少的数据,更频繁的刷新输出-z, --null-data使用 NUL 字符分隔各行--help     打印帮助并退出--version  输出版本信息并退出如果没有 -e, --expression, -f 或 --file 选项,那么第一个非选项参数被视为
sed脚本。其他非选项参数被视为输入文件,如果没有输入文件,那么程序将从标准
输入读取数据。

awk

man awk

Tips:awk的详细用法,以后有空再更新。。。

MAWK(1)                                                                         USER COMMANDS                                                                        MAWK(1)NAMEmawk - pattern scanning and text processing languageSYNOPSISmawk [-W option] [-F value] [-v var=value] [--] 'program text' [file ...]mawk [-W option] [-F value] [-v var=value] [-f program-file] [--] [file ...]DESCRIPTIONmawk is an interpreter for the AWK Programming Language.  The AWK language is useful for manipulation of data files, text retrieval and processing, and for prototyp‐ing and experimenting with algorithms.  mawk is a new awk meaning it implements the AWK language as defined in Aho, Kernighan and  Weinberger,  The  AWK  ProgrammingLanguage,  Addison-Wesley  Publishing, 1988.  (Hereafter referred to as the AWK book.)  mawk conforms to the Posix 1003.2 (draft 11.3) definition of the AWK languagewhich contains a few features not described in the AWK book,  and mawk provides a small number of extensions.An AWK program is a sequence of pattern {action} pairs and function definitions.  Short programs are entered on the command line usually enclosed in  '  '  to  avoidshell  interpretation.   Longer programs can be read in from a file with the -f option.  Data  input is read from the list of files on the command line or from stan‐dard input when the list is empty.  The input is broken into records as determined by the record separator variable, RS.  Initially, RS = "\n" and records  are  syn‐onymous with lines.  Each record is compared against each pattern and if it matches, the program text for {action} is executed.OPTIONS-F value       sets the field separator, FS, to value.-f file        Program text is read from file instead of from the command line.  Multiple -f options are allowed.-v var=value   assigns value to program variable var.--             indicates the unambiguous end of options.The above options will be available with any Posix compatible implementation of AWK, and implementation specific options are prefaced with -W.  mawk provides six:-W version     mawk writes its version and copyright to stdout and compiled limits to stderr and exits 0.-W dump        writes an assembler like listing of the internal representation of the program to stdout and exits 0 (on successful compilation).-W interactive sets unbuffered writes to stdout and line buffered reads from stdin.  Records from stdin are lines regardless of the value of RS.-W exec file   Program text is read from file and this is the last option. Useful on systems that support the #!  "magic number" convention for executable scripts.-W sprintf=num adjusts the size of mawk's internal sprintf buffer to num bytes.  More than rare use of this option indicates mawk should be recompiled.-W posix_space forces mawk not to consider '\n' to be space.The short forms -W[vdiesp] are recognized and on some systems -We is mandatory to avoid command line length limitations.THE AWK LANGUAGE1. Program structureAn AWK program is a sequence of pattern {action} pairs and user function definitions.A pattern can be:BEGINENDexpressionexpression , expressionOne,  but  not  both, of pattern {action} can be omitted.   If {action} is omitted it is implicitly { print }.  If pattern is omitted, then it is implicitly matched.BEGIN and END patterns require an action.Statements are terminated by newlines, semi-colons or both.  Groups of statements such as actions or loop bodies are blocked via { ... } as in C.  The last statementin a block doesn't need a terminator.  Blank lines have no meaning; an empty statement is terminated with a semi-colon. Long statements can be continued with a back‐slash, \.  A statement can be broken without a backslash after a comma, left brace, &&, ||, do, else, the right parenthesis of an if, while or for statement, and theright parenthesis of a function definition.  A comment starts with # and extends to, but does not include the end of line.The following statements control program flow inside blocks.if ( expr ) statementif ( expr ) statement else statementwhile ( expr ) statementdo statement while ( expr )for ( opt_expr ; opt_expr ; opt_expr ) statementfor ( var in array ) statementcontinuebreak2. Data types, conversion and comparisonThere  are  two  basic data types, numeric and string.  Numeric constants can be integer like -2, decimal like 1.08, or in scientific notation like -1.1e4 or .28E-3.All numbers are represented internally and all computations are done in floating point arithmetic.  So for example, the expression 0.2e2 == 20 is true  and  true  isrepresented as 1.0.String constants are enclosed in double quotes."This is a string with a newline at the end.\n"Strings can be continued across a line by escaping (\) the newline.  The following escape sequences are recognized.\\        \\"        "\a        alert, ascii 7\b        backspace, ascii 8\t        tab, ascii 9\n        newline, ascii 10\v        vertical tab, ascii 11\f        formfeed, ascii 12\r        carriage return, ascii 13\ddd      1, 2 or 3 octal digits for ascii ddd\xhh      1 or 2 hex digits for ascii  hhIf you escape any other character \c, you get \c, i.e., mawk ignores the escape.There  are  really three basic data types; the third is number and string which has both a numeric value and a string value at the same time.  User defined variablescome into existence when first referenced and are initialized to null, a number and string value which has numeric value 0 and string value "".   Non-trivial  numberand string typed data come from input and are typically stored in fields.  (See section 4).The type of an expression is determined by its context and automatic type conversion occurs if needed.  For example, to evaluate the statementsy = x + 2  ;  z = x  "hello"The  value  stored  in variable y will be typed numeric.  If x is not numeric, the value read from x is converted to numeric before it is added to 2 and stored in y.The value stored in variable z will be typed string, and the value of x will be converted to string if necessary and concatenated  with  "hello".   (Of  course,  thevalue  and  type  stored  in  x is not changed by any conversions.)  A string expression is converted to numeric using its longest numeric prefix as with atof(3).  Anumeric expression is converted to string by replacing expr with sprintf(CONVFMT, expr), unless expr can be represented on the host machine as an exact integer  thenit  is  converted  to sprintf("%d", expr).  Sprintf() is an AWK built-in that duplicates the functionality of sprintf(3), and CONVFMT is a built-in variable used forinternal conversion from number to string and initialized to "%.6g".  Explicit type conversions can be forced, expr "" is string and expr+0 is numeric.To evaluate, expr1 rel-op expr2, if both operands are numeric or number and string then the comparison is numeric; if both operands  are  string  the  comparison  isstring; if one operand is string, the non-string operand is converted and the comparison is string.  The result is numeric, 1 or 0.In  boolean  contexts  such as, if ( expr ) statement, a string expression evaluates true if and only if it is not the empty string ""; numeric values if and only ifnot numerically zero.3. Regular expressionsIn the AWK language, records, fields and strings are often tested for matching a regular expression.  Regular expressions are enclosed in slashes, andexpr ~ /r/is an AWK expression that evaluates to 1 if expr "matches" r, which means a substring of expr is in the set of strings defined by r.  With no  match  the  expressionevaluates to 0; replacing ~ with the "not match" operator, !~ , reverses the meaning.  As  pattern-action pairs,/r/ { action }   and   $0 ~ /r/ { action }are  the same, and for each input record that matches r, action is executed.  In fact, /r/ is an AWK expression that is equivalent to ($0 ~ /r/) anywhere except whenon the right side of a match operator or passed as an argument to a built-in function that expects a regular expression argument.AWK uses extended regular expressions as with egrep(1).  The regular expression metacharacters, i.e., those with special meaning in regular expressions are^ $ . [ ] | ( ) * + ?Regular expressions are built up from characters as follows:c            matches any non-metacharacter c.\c           matches a character defined by the same escape sequences used in string constants or the literal character c if \c is not an escape sequence..            matches any character (including newline).^            matches the front of a string.$            matches the back of a string.[c1c2c3...]  matches any character in the class c1c2c3... .  An interval of characters is denoted c1-c2 inside a class [...].[^c1c2c3...] matches any character not in the class c1c2c3...Regular expressions are built up from other regular expressions as follows:r1r2         matches r1 followed immediately by r2 (concatenation).r1 | r2      matches r1 or r2 (alternation).r*           matches r repeated zero or more times.r+           matches r repeated one or more times.r?           matches r zero or once.(r)          matches r, providing grouping.The increasing precedence of operators is alternation, concatenation and unary (*, + or ?).For example,/^[_a-zA-Z][_a-zA-Z0-9]*$/  and/^[-+]?([0-9]+\.?|\.[0-9])[0-9]*([eE][-+]?[0-9]+)?$/are matched by AWK identifiers and AWK numeric constants respectively.  Note that . has to be escaped to be recognized as a decimal point,  and  that  metacharactersare not special inside character classes.Any  expression can be used on the right hand side of the ~ or !~ operators or passed to a built-in that expects a regular expression.  If needed, it is converted tostring, and then interpreted as a regular expression.  For example,BEGIN { identifier = "[_a-zA-Z][_a-zA-Z0-9]*" }$0 ~ "^" identifierprints all lines that start with an AWK identifier.mawk recognizes the empty regular expression, //, which matches the empty string and hence is matched by any string at the front, back and between  every  character.For example,echo  abc | mawk { gsub(//, "X") ; print }XaXbXcX4. Records and fieldsRecords are read in one at a time, and stored in the field variable $0.  The record is split into fields which are stored in $1, $2, ..., $NF.  The built-in variableNF is set to the number of fields, and NR and FNR are incremented by 1.  Fields above $NF are set to "".Assignment to $0 causes the fields and NF to be recomputed.  Assignment to NF or to a field causes $0 to be reconstructed by concatenating the $i's separated by OFS.Assignment to a field with index greater than NF, increases NF and causes $0 to be reconstructed.Data input stored in fields is string, unless the entire field has numeric form and then the type is number and string.  For example,echo 24 24E |mawk '{ print($1>100, $1>"100", $2>100, $2>"100") }'0 1 1 1$0  and  $2  are string and $1 is number and string.  The first comparison is numeric, the second is string, the third is string (100 is converted to "100"), and thelast is string.5. Expressions and operatorsThe expression syntax is similar to C.  Primary expressions are numeric constants, string constants, variables, fields, arrays and function  calls.   The  identifierfor  a  variable,  array  or function can be a sequence of letters, digits and underscores, that does not start with a digit.  Variables are not declared; they existwhen first referenced and are initialized to null.New expressions are composed with the following operators in order of increasing precedence.assignment          =  +=  -=  *=  /=  %=  ^=conditional         ?  :logical or          ||logical and         &&array membership    inmatching       ~   !~relational          <  >   <=  >=  ==  !=concatenation       (no explicit operator)add ops             +  -mul ops             *  /  %unary               +  -logical not         !exponentiation      ^inc and dec         ++ -- (both post and pre)field               $Assignment, conditional and exponentiation associate right to left; the other operators associate left to right.  Any expression can be parenthesized.6. ArraysAwk provides one-dimensional arrays.  Array elements are expressed as array[expr].  Expr is internally converted to string type, so, for example, A[1] and A["1"] arethe  same  element  and  the  actual  index is "1".  Arrays indexed by strings are called associative arrays.  Initially an array is empty; elements exist when firstaccessed.  An expression, expr in array evaluates to 1 if array[expr] exists, else to 0.There is a form of the for statement that loops over each index of an array.for ( var in array ) statementsets var to each index of array and executes statement.  The order that var transverses the indices of array is not defined.The statement, delete array[expr], causes array[expr] not to exist.  mawk supports an extension, delete array, which deletes all elements of array.Multidimensional arrays are synthesized with concatenation using the built-in variable SUBSEP.  array[expr1,expr2] is equivalent to array[expr1 SUBSEP expr2].  Test‐ing for a multidimensional element uses a parenthesized index, such asif ( (i, j) in A )  print A[i, j]7. Builtin-variablesThe following variables are built-in and initialized before program execution.ARGC      number of command line arguments.ARGV      array of command line arguments, 0..ARGC-1.CONVFMT   format for internal conversion of numbers to string, initially = "%.6g".ENVIRON   array indexed by environment variables.  An environment string, var=value is stored as ENVIRON[var] = value.FILENAME  name of the current input file.FNR       current record number in FILENAME.FS        splits records into fields as a regular expression.NF        number of fields in the current record.NR        current record number in the total input stream.OFMT      format for printing numbers; initially = "%.6g".OFS       inserted between fields on output, initially = " ".ORS       terminates each record on output, initially = "\n".RLENGTH   length set by the last call to the built-in function, match().RS        input record separator, initially = "\n".RSTART    index set by the last call to match().SUBSEP    used to build multiple array subscripts, initially = "\034".8. Built-in functionsString functionsgsub(r,s,t)  gsub(r,s)Global substitution, every match of regular expression r in variable t is replaced by string s.  The number of replacements is returned.  If t is omit‐ted, $0 is used.  An & in the replacement string s is replaced by the matched substring of t.  \& and \\ put  literal & and  \,  respectively,  in  thereplacement string.index(s,t)If t is a substring of s, then the position where t starts is returned, else 0 is returned.  The first character of s is in position 1.length(s)Returns the length of string s.match(s,r)Returns  the  index  of  the  first  longest match of regular expression r in string s.  Returns 0 if no match.  As a side effect, RSTART is set to thereturn value.  RLENGTH is set to the length of the match or -1 if no match.  If the empty string is matched, RLENGTH is set to 0, and 1 is returned  ifthe match is at the front, and length(s)+1 is returned if the match is at the back.split(s,A,r)  split(s,A)String  s is split into fields by regular expression r and the fields are loaded into array A.  The number of fields is returned.  See section 11 belowfor more detail.  If r is omitted, FS is used.sprintf(format,expr-list)Returns a string constructed from expr-list according to format.  See the description of printf() below.sub(r,s,t)  sub(r,s)Single substitution, same as gsub() except at most one substitution.substr(s,i,n)  substr(s,i)Returns the substring of string s, starting at index i, of length n.  If n is omitted, the suffix of s, starting at i is returned.tolower(s)Returns a copy of s with all upper case characters converted to lower case.toupper(s)Returns a copy of s with all lower case characters converted to upper case.Arithmetic functionsatan2(y,x)     Arctan of y/x between -pi and pi.cos(x)         Cosine function, x in radians.exp(x)         Exponential function.int(x)         Returns x truncated towards zero.log(x)         Natural logarithm.rand()         Returns a random number between zero and one.sin(x)         Sine function, x in radians.sqrt(x)        Returns square root of x.srand(expr)  srand()Seeds the random number generator, using the clock if expr is omitted, and returns the value of the previous seed.  mawk seeds the random number gener‐ator from the clock at startup so there is no real need to call srand().  Srand(expr) is useful for repeating pseudo random sequences.9. Input and outputThere are two output statements, print and printf.print  writes $0  ORS to standard output.print expr1, expr2, ..., exprnwrites expr1 OFS expr2 OFS ... exprn ORS to standard output.  Numeric expressions are converted to string with OFMT.printf format, expr-listduplicates the printf C library function writing to standard output.  The complete ANSI C format specifications are recognized with conversions %c, %d,%e, %E, %f, %g, %G, %i, %o, %s, %u, %x, %X and %%, and conversion qualifiers h and l.The argument list to print or printf can optionally be enclosed in parentheses.  Print formats numbers using OFMT or "%d" for exact integers.  "%c"  with  a  numericargument  prints  the corresponding 8 bit character, with a string argument it prints the first character of the string.  The output of print and printf can be redi‐rected to a file or command by appending > file, >> file or | command to the end of the print statement.  Redirection opens file or  command  only  once,  subsequentredirections append to the already open stream.  By convention, mawk associates the filename "/dev/stderr" with stderr which allows print and printf to be redirectedto stderr.  mawk also associates "-" and "/dev/stdout" with stdin and stdout which allows these streams to be passed to functions.The input function getline has the following variations.getlinereads into $0, updates the fields, NF, NR and FNR.getline < filereads into $0 from file, updates the fields and NF.getline varreads the next record into var, updates NR and FNR.getline var < filereads the next record of file into var.command | getlinepipes a record from command into $0 and updates the fields and NF.command | getline varpipes a record from command into var.Getline returns 0 on end-of-file, -1 on error, otherwise 1.Commands on the end of pipes are executed by /bin/sh.The function close(expr) closes the file or pipe associated with expr.  Close returns 0 if expr is an open file, the exit status if expr is a piped command,  and  -1otherwise.  Close is used to reread a file or command, make sure the other end of an output pipe is finished or conserve file resources.The  function fflush(expr) flushes the output file or pipe associated with expr.  Fflush returns 0 if expr is an open output stream else -1.  Fflush without an argu‐ment flushes stdout.  Fflush with an empty argument ("") flushes all open output.The function system(expr) uses /bin/sh to execute expr and returns the exit status of the command expr.  Changes made to the ENVIRON array are not passed to commandsexecuted with system or pipes.10. User defined functionsThe syntax for a user defined function isfunction name( args ) { statements }The function body can contain a return statementreturn opt_exprA  return statement is not required.  Function calls may be nested or recursive.  Functions are passed expressions by value and arrays by reference.  Extra argumentsserve as local variables and are initialized to null.  For example, csplit(s,A) puts each character of s into array A and returns the length of s.function csplit(s, A,    n, i){n = length(s)for( i = 1 ; i <= n ; i++ ) A[i] = substr(s, i, 1)return n}Putting extra space between passed arguments and local variables is conventional.  Functions can be referenced before they are defined, but the function name and the'(' of the arguments must touch to avoid confusion with concatenation.11. Splitting strings, records and filesAwk  programs  use  the  same  algorithm to split strings into arrays with split(), and records into fields on FS.  mawk uses essentially the same algorithm to splitfiles into records on RS.Split(expr,A,sep) works as follows:(1)    If sep is omitted, it is replaced by FS.  Sep can be an expression or regular expression.  If it is an expression of non-string type, it  is  convertedto string.(2)    If  sep  = " " (a single space), then <SPACE> is trimmed from the front and back of expr, and sep becomes <SPACE>.  mawk defines <SPACE> as the regularexpression /[ \t\n]+/.  Otherwise sep is treated as a regular expression, except that meta-characters are ignored for  a  string  of  length  1,  e.g.,split(x, A, "*") and split(x, A, /\*/) are the same.(3)    If expr is not string, it is converted to string.  If expr is then the empty string "", split() returns 0 and A is set empty.  Otherwise, all non-over‐lapping, non-null and longest matches of sep in expr, separate expr into fields which are loaded into A.  The fields are placed  in  A[1],  A[2],  ...,A[n]  and  split()  returns  n,  the number of fields which is the number of matches plus one.  Data placed in A that looks numeric is typed number andstring.Splitting records into fields works the same except the pieces are loaded into $1, $2,..., $NF.  If $0 is empty, NF is set to 0 and all $i to "".mawk splits files into records by the same algorithm, but with the slight difference that RS is really a terminator instead of a separator.  (ORS is really a  termi‐nator too).E.g.,  if  FS  =  ":+"  and $0 = "a::b:" , then NF = 3 and $1 = "a", $2 = "b" and $3 = "", but if "a::b:" is the contents of an input file and RS = ":+", thenthere are two records "a" and "b".RS = " " is not special.If FS = "", then mawk breaks the record into individual characters, and, similarly, split(s,A,"") places the individual characters of s into A.12. Multi-line recordsSince mawk interprets RS as a regular expression, multi-line records are easy.  Setting RS = "\n\n+", makes one or more blank lines separate records.  If FS  =  "  "(the default), then single newlines, by the rules for <SPACE> above, become space and single newlines are field separators.For  example, if a file is "a b\nc\n\n", RS = "\n\n+" and FS = " ", then there is one record "a b\nc" with three fields "a", "b" and "c".  Changing FS = "\n",gives two fields "a b" and "c"; changing FS = "", gives one field identical to the record.If you want lines with spaces or tabs to be considered blank, set RS = "\n([ \t]*\n)+".  For compatibility with other awks, setting RS = "" has the same effect as ifblank lines are stripped from the front and back of files and then records are determined as if RS = "\n\n+".  Posix requires that "\n" always separates records whenRS = "" regardless of the value of FS.  mawk does not support this convention, because defining "\n" as <SPACE> makes it unnecessary.Most of the time when you change RS for multi-line records, you will also want to change ORS to "\n\n" so the record spacing is preserved on output.13. Program executionThis section describes the order of program execution.  First ARGC is set to the total number of command line arguments passed to the execution phase of the program.ARGV[0] is set the name of the AWK interpreter and ARGV[1] ...  ARGV[ARGC-1] holds the remaining command line arguments exclusive of options and program source.  Forexample withmawk  -f  prog  v=1  A  t=hello  BARGC = 5 with ARGV[0] = "mawk", ARGV[1] = "v=1", ARGV[2] = "A", ARGV[3] = "t=hello" and ARGV[4] = "B".Next, each BEGIN block is executed in order.  If the program consists entirely of BEGIN blocks, then execution terminates, else an input stream is opened and  execu‐tion continues.  If ARGC equals 1, the input stream is set to stdin, else  the command line arguments ARGV[1] ...  ARGV[ARGC-1] are examined for a file argument.The  command  line  arguments  divide  into  three  sets: file arguments, assignment arguments and empty strings "".  An assignment has the form var=string.  When anARGV[i] is examined as a possible file argument, if it is empty it is skipped; if it is an assignment argument, the assignment to var takes place and i skips to  thenext  argument;  else ARGV[i] is opened for input.  If it fails to open, execution terminates with exit code 2.  If no command line argument is a file argument, theninput comes from stdin.  Getline in a BEGIN action opens input.  "-" as a file argument denotes stdin.Once an input stream is open, each input record is tested against each pattern, and if it matches, the associated action is executed.  An expression pattern  matchesif  it is boolean true (see the end of section 2).  A BEGIN pattern matches before any input has been read, and an END pattern matches after all input has been read.A range pattern, expr1,expr2 , matches every record between the match of expr1 and the match expr2 inclusively.When end of file occurs on the input stream, the remaining command line arguments are examined for a file argument, and if there is one it is opened,  else  the  ENDpattern is considered matched and all END actions are executed.In  the  example,  the assignment v=1 takes place after the BEGIN actions are executed, and the data placed in v is typed number and string.  Input is then read fromfile A.  On end of file A, t is set to the string "hello", and B is opened for input.  On end of file B, the END actions are executed.Program flow at the pattern {action} level can be changed with thenextexit  opt_exprstatements.  A next statement causes the next input record to be read and pattern testing to restart with the first pattern {action} pair in the  program.   An  exitstatement  causes immediate execution of the END actions or program termination if there are none or if the exit occurs in an END action.  The opt_expr sets the exitvalue of the program unless overridden by a later exit or subsequent error.EXAMPLES1. emulate cat.{ print }2. emulate wc.{ chars += length($0) + 1  # add one for the \nwords += NF}END{ print NR, words, chars }3. count the number of unique "real words".BEGIN { FS = "[^A-Za-z]+" }{ for(i = 1 ; i <= NF ; i++)  word[$i] = "" }END { delete word[""]for ( i in word )  cnt++print cnt}4. sum the second field of every record based on the first field.$1 ~ /credit|gain/ { sum += $2 }$1 ~ /debit|loss/  { sum -= $2 }END { print sum }5. sort a file, comparing as string{ line[NR] = $0 "" }  # make sure of comparison type# in case some lines look numericEND {  isort(line, NR)for(i = 1 ; i <= NR ; i++) print line[i]}#insertion sort of A[1..n]function isort( A, n,    i, j, hold){for( i = 2 ; i <= n ; i++){hold = A[j = i]while ( A[j-1] > hold ){ j-- ; A[j+1] = A[j] }A[j] = hold}# sentinel A[0] = "" will be created if needed}COMPATIBILITY ISSUESThe Posix 1003.2(draft 11.3) definition of the AWK language is AWK as described in the AWK book with a few extensions that appeared in SystemVR4 nawk. The extensionsare:New functions: toupper() and tolower().New variables: ENVIRON[] and CONVFMT.ANSI C conversion specifications for printf() and sprintf().New command options:  -v var=value, multiple -f options and implementation options as arguments to -W.Posix AWK is oriented to operate on files a line at a time.  RS can be changed from "\n" to another single character, but it is hard to find any use for this — thereare no examples in the AWK book.  By convention, RS = "", makes one or more blank lines separate records, allowing multi-line records.  When RS = "", "\n" is  alwaysa field separator regardless of the value in FS.mawk, on the other hand, allows RS to be a regular expression.  When "\n" appears in records, it is treated as space, and FS always determines fields.Removing the line at a time paradigm can make some programs simpler and can often improve performance.  For example, redoing example 3 from above,BEGIN { RS = "[^A-Za-z]+" }{ word[ $0 ] = "" }END { delete  word[ "" ]for( i in word )  cnt++print cnt}counts the number of unique words by making each word a record.  On moderate size files, mawk executes twice as fast, because of the simplified inner loop.The following program replaces each comment by a single space in a C program file,BEGIN {RS = "/\*([^*]|\*+[^/*])*\*+/"# comment is record separatorORS = " "getline  hold}{ print hold ; hold = $0 }END { printf "%s" , hold }Buffering one record is needed to avoid terminating the last record with a space.With mawk, the following are all equivalent,x ~ /a\+b/    x ~ "a\+b"     x ~ "a\\+b"The  strings  get  scanned  twice, once as string and once as regular expression.  On the string scan, mawk ignores the escape on non-escape characters while the AWKbook advocates \c be recognized as c which necessitates the double escaping of meta-characters in strings.  Posix explicitly declines to define  the  behavior  whichpassively forces programs that must run under a variety of awks to use the more portable but less readable, double escape.Posix  AWK  does  not recognize "/dev/std{out,err}" or \x hex escape sequences in strings.  Unlike ANSI C, mawk limits the number of digits that follows \x to two asthe current implementation only supports 8 bit characters.  The built-in fflush first appeared in a recent (1993) AT&T awk released to netlib, and is not part of theposix standard.  Aggregate deletion with delete array is not part of the posix standard.Posix  explicitly leaves the behavior of FS = "" undefined, and mentions splitting the record into characters as a possible interpretation, but currently this use isnot portable across implementations.Finally, here is how mawk handles exceptional cases not discussed in the AWK book or the Posix draft.  It is unsafe to assume consistency across  awks  and  safe  toskip to the next section.substr(s,  i,  n) returns the characters of s in the intersection of the closed interval [1, length(s)] and the half-open interval [i, i+n).  When this inter‐section is empty, the empty string is returned; so substr("ABC", 1, 0) = "" and substr("ABC", -4, 6) = "A".Every string, including the empty string, matches the empty string at the front so, s ~ // and s ~ "", are always 1 as is match(s, //) and match(s, "").   Thelast two set RLENGTH to 0.index(s, t) is always the same as match(s, t1) where t1 is the same as t with metacharacters escaped.  Hence consistency with match requires that index(s, "")always returns 1.  Also the condition, index(s,t) != 0 if and only t is a substring of s, requires index("","") = 1.If getline encounters end of file, getline var, leaves var unchanged.  Similarly, on entry to the END actions, $0, the fields and NF have  their  value  unal‐tered from the last record.SEE ALSOegrep(1)Aho,  Kernighan  and  Weinberger,  The  AWK  Programming Language, Addison-Wesley Publishing, 1988, (the AWK book), defines the language, opening with a tutorial andadvancing to many interesting programs that delve into issues of software design and analysis relevant to programming in any language.The GAWK Manual, The Free Software Foundation, 1991, is a tutorial and language reference that does not attempt the depth of the AWK book and assumes the reader  maybe a novice programmer.  The section on AWK arrays is excellent.  It also discusses Posix requirements for AWK.BUGSmawk cannot handle ascii NUL \0 in the source or data files.  You can output NUL using printf with %c, and any other 8 bit character is acceptable input.mawk  implements  printf()  and sprintf() using the C library functions, printf and sprintf, so full ANSI compatibility requires an ANSI C library.  In practice thismeans the h conversion qualifier may not be available.  Also mawk inherits any bugs or limitations of the library functions.Implementors of the AWK language have shown a consistent lack of imagination when naming their programs.AUTHORMike Brennan (brennan@whidbey.com).Version 1.2                                                                      Dec 22 1994                                                                         MAWK(1)

Linux常用命令

dd命令

ssh命令

tar命令

curl命令

top命令

tr命令

xargs命令

sort命令

du/df/free命令

。。。。待补充。。。。

shell 知识

function的使用

  1. shell的函数不能有参数列表
  2. 函数内部可以改变全局变量
a=10
function func1(){#echo "hello"#cd /home#touch a.txta=3
}
func1
echo a   #应该输出3

这也是前两天面试官问我的问题,我还是没有答出来。。。。😅😅😅

其他内容,以后补充。。。。

相关文章:

Linux常用命令shell常用知识 。。。。面试被虐之后,吐血整理。。。。

Linux三剑客&常用命令&shell常识 Linux三剑客grep - print lines matching a patternsed - stream editor for filtering and transforming textawkman awk Linux常用命令dd命令ssh命令tar命令curl命令top命令tr命令xargs命令sort命令du/df/free命令 shell 知识functio…...

压力测试指南-压力测试基础入门

压力测试基础入门 在当今快速迭代的软件开发环境中&#xff0c;确保应用程序在高负载情况下仍能稳定运行变得至关重要。这正是压力测试大显身手的时刻。本文将带领您深入了解压力测试的基础知识&#xff0c;介绍实用工具&#xff0c;并指导您设计、执行压力测试&#xff0c;最…...

Linux:LCD驱动开发

目录 1.不同接口的LCD硬件操作原理 应用工程师眼中看到的LCD 1.1像素的颜色怎么表示 ​编辑 1.2怎么把颜色发给LCD 驱动工程师眼中看到的LCD 统一的LCD硬件模型 8080接口 TFTRGB接口 什么是MIPI Framebuffer驱动程序框架 怎么编写Framebuffer驱动框架 硬件LCD时序分析…...

QT:常用类与组件

1.设计QQ的界面 widget.h #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QPushButton> #include <QLineEdit> #include <QLabel>//自定义类Widget,采用public方式继承QWidget&#xff0c;该类封装了图形化界面的相关操作&#xff…...

企业内训|提示词工程师高阶技术内训-某运营商研发团队

近日&#xff0c;TsingtaoAI为某运营商技术团队交付提示词工程师高级技术培训&#xff0c;本课程为期2天&#xff0c;深入探讨深度学习与大模型技术在提示词生成与优化、客服大模型产品设计等业务场景中的应用。内容涵盖了深度学习前沿理论、大模型技术架构设计与优化、以及如何…...

K8S真正删除pod

假设k8s的某个命名空间如&#xff08;default&#xff09;有一个运行nginx 的pod&#xff0c;而这个pod是以kubectl run pod命令运行的 1.错误示范&#xff1a; kubectl delete pod nginx-2756690723-hllbp 结果显示这个pod 是删除了&#xff0c;但k8s很快自动创建新的pod,但是…...

数据结构:队列及其应用

队列&#xff08;Queue&#xff09;是一种特殊的线性表&#xff0c;它的主要特点是先进先出&#xff08;First In First Out&#xff0c;FIFO&#xff09;。队列只允许在一端&#xff08;队尾&#xff09;进行插入操作&#xff0c;而在另一端&#xff08;队头&#xff09;进行删…...

26个用好AI大模型的提示词技巧

如果你已深入探索过ChatGPT、Microsoft Copilot、风变AI等前沿的生成式AI工具&#xff0c;那么你对“prompt”&#xff08;提示词&#xff09;这一核心概念一定有自己的认知。 作为连接你与AI创意源泉的桥梁&#xff0c;“prompt”不仅是触发无限想象的钥匙&#xff0c;更是塑…...

线性表二——栈stack

第一题 #include<bits/stdc.h> using namespace std; stack<char> s; int n; string ced;//如何匹配 出现的右括号转换成同类型的左括号&#xff0c;方便我们直接和栈顶元素 char cheak(char c){if(c)) return (;if(c]) return [;if(c}) return {;return \0;/…...

浏览器发送请求后关闭,服务器的处理过程

之前在开发中&#xff0c;有些后端服务处理非常慢&#xff0c;页面可能会出现504 Gateway time-out的提示&#xff0c;或者服务器还没返回数据&#xff0c;浏览器就关掉了。我们只是看到了浏览器关掉&#xff0c;但是服务器和客户端的状态都是什么样的呢&#xff1f; 问题 在…...

tee命令:轻松同步输出到屏幕与文件

一、命令简介 ​tee​ 命令在 Linux 和 Unix 系统中用于读取标准输入的数据&#xff0c;并将其同时输出到标准输出和文件中。简单来说&#xff0c;tee​ 命令可以用来分割数据流&#xff0c;使其既能够被输出到屏幕&#xff0c;也能够被写入到文件中。 ​​ ‍ 二、命令参数…...

【经验技巧】如何做好S参数的仿测一致性

根据个人经验,想要做好电路板S参数的仿测一致性,如下的相关信息必须被认真对待: 1. PCB叠构(Stack up),仿真模型需要保证设计参数与板厂供应商的生产参数完全一样,这些参数包括: 叠层结构数据;介电常数;损耗因子;蚀刻因子;表面粗糙度。 2. 仿真中,需要保证信号测试…...

js逆向——webpack实战案例(一)

今日受害者网站&#xff1a;https://www.iciba.com/translate?typetext 首先通过跟栈的方法找到加密位置 我们跟进u函数&#xff0c;发现是通过webpack加载的 向上寻找u的加载位置&#xff0c;然后打上断点&#xff0c;刷新网页&#xff0c;让程序断在加载函数的位置 u r.n…...

Spring Boot 进阶-Spring Boot的全局异常处理机制详解

我们知道在软件运行的过程中,总会出现各种各样的问题,各种各样的异常,而程序员的主要任务之一就是解决在程序运行过程中出现的这些异常。在很多程序员开发的代码中我们会看到在关键的地方为了保证程序能够有一个正常的反馈,大量地使用了try catch finally语句。 大量的try …...

滚雪球学MySQL[7.1讲]:安全管理

全文目录&#xff1a; 前言7. 安全管理7.1 用户与权限管理7.1.1 创建和管理用户7.1.2 权限分配与管理7.1.3 最小权限原则 7.2 安全策略配置7.2.1 使用加密连接7.2.2 强密码策略7.2.3 定期审计和日志管理 7.3 SQL注入防范7.3.1 使用预处理语句7.3.2 输入验证与清理7.3.3 最小化数…...

反射及其应用---->2

目录 1.使用类对象 1.1创建对象 1.2使用对象属性 1.3使用方法 2.反射操作数组 3.反射获得泛型 4.类加载器 4.1双亲委派机制 4.2自定义加载器 1.使用类对象 通过反射使用类对象&#xff0c;主要体现3个部分 创建对象&#xff0c;调用方法&#xff0c;调用属性&#xff…...

[Python学习日记-32] Python 中的函数的返回值与作用域

[Python学习日记-32] Python 中的函数的返回值与作用域 简介 返回值 作用域 简介 在函数的介绍中我们提到了函数的返回值&#xff0c;当时只是做了简单的介绍&#xff0c;下面我们将会进行详细的介绍和演示&#xff0c;同时也会讲一下 Python 中的作用域&#xff0c;作用域分…...

儿童发光耳勺值得买吗?儿童发光耳勺最建议买的五个牌子!

儿童耳部清洁需谨慎&#xff0c;发光耳勺能在光线不足时提供照明&#xff0c;便于看清耳道。但不同产品质量参差不齐&#xff0c;选择时需综合考虑安全性、实用性等因素&#xff0c;为孩子的耳部健康做出正确选择&#xff01; 这里给大家总结了全新的儿童发光耳勺的避雷指南&am…...

TIPS 二进制程序暴露符号给动态链接库使用

背景 在支持插件/扩展的C/C系统中&#xff0c;通常会支持在程序运行时加载动态链接库。这时二进制程序会提供一些函数/接口让动态链接库调用&#xff0c;但是这些函数在二进制程序中又不会使用&#xff0c;导致在编译时编译器直接把这些符号删除了&#xff0c;加载链接库就会由…...

【分布式微服务云原生】8分钟掌握微服务通信的艺术:Dubbo与OpenFeign全面解析

摘要&#xff1a; 在构建微服务架构时&#xff0c;服务间的通信机制是核心要素之一。Dubbo和OpenFeign是两个非常流行的服务调用框架&#xff0c;它们各有千秋&#xff0c;适用于不同的场景。本文将深入探讨Dubbo和OpenFeign的主要特点、使用场景以及它们之间的差异&#xff0c…...

sicp每日一题[2.33]

Exercise 2.33 Fill in the missing expressions to complete the following definitions of some basic list-manipulation operations as accumulations: ; p 表示一个函数&#xff0c;sequence 表示一个列表 ; 这个函数将对列表中每一个元素进行 p 操作 (define (map p sequ…...

【Mybatis】常见面试题汇总 共56题

文章目录 1. 介绍下MyBatis?2. MyBatis 框架的应用场景?3. MyBatis 有哪些优点?4. MyBatis 有哪些缺点?5. MyBatis 用到了哪些设计模式&#xff1f;6. MyBatis常用注解有哪些&#xff1f;7. MyBatis 有哪些核心组件?8. MyBatis编程步骤是什么样的&#xff1f;9. MyBatis 和…...

每天一道面试题(17):服务网格学习笔记

什么是服务网格&#xff1f; 服务网格&#xff08;Service Mesh&#xff09;是处理微服务间通信的一种基础设施层。它主要用于解耦服务间的通信与业务逻辑&#xff0c;使开发者可以专注于业务实现。服务网格在微服务架构的演进中扮演了重要角色&#xff0c;特别是在解决服务间…...

【nrm】npm 注册表管理器

nrm是什么 nrm&#xff08;NPM Registry Manager&#xff09;是一个用于管理 Node.js 包管理器&#xff08;如 npm 和 Yarn&#xff09;的注册表工具。它可以帮助用户快速切换不同的 npm 源&#xff0c;以便于提高包安装的速度和效率&#xff0c;特别是在中国大陆地区&#xf…...

解压短视频素材资源网站推荐

如果你正在寻找解压短视频素材&#xff0c;那么这篇文章正是为你而写&#xff01;以下是一些热门的网站&#xff0c;帮助你轻松找到所需的素材&#xff0c;快来看看吧&#xff01; 蛙学网 蛙学网是国内领先的视频素材网站&#xff0c;提供丰富的解压视频素材。无论是放松心情的…...

Qemu开发ARM篇-6、emmc/SD卡AB分区镜像制作并通过uboot进行挂载启动

文章目录 1、AB分区镜像制作2、uboot修改3、镜像启动 在上一篇 Qemu开发ARM篇-5、buildroot制作根文件系统并挂载启动中&#xff0c;我们通过buildroot制作了根文件系统&#xff0c;并通过 SD卡的形式将其挂载到设备并成功进行了启动&#xff0c;但上一章中&#xff0c;我们的…...

Spring Boot中使用ThreadPoolTaskScheduler实现轻量级多线程定时任务

引言 在Java开发中&#xff0c;Spring Boot提供了多种方式来执行定时任务&#xff0c;如Scheduled注解和TaskScheduler。当需要执行多线程定时任务时&#xff0c;ThreadPoolTaskScheduler是一个轻量级的解决方案。本文将通过一个具体的业务场景&#xff0c;介绍如何使用Thread…...

完全二叉树的节点个数 C++ 简单问题

完全二叉树 的定义如下&#xff1a;在完全二叉树中&#xff0c;除了最底层节点可能没填满外&#xff0c;其余每层节点数都达到最大值&#xff0c;并且最下面一层的节点都集中在该层最左边的若干位置。若最底层为第 h 层&#xff0c;则该层包含 1~ 2h 个节点。 示例 1&#xff…...

每日一题学习笔记

给你两个字符串&#xff1a;ransomNote 和 magazine &#xff0c;判断 ransomNote 能不能由 magazine 里面的字符构成。 如果可以&#xff0c;返回 true &#xff1b;否则返回 false 。 magazine 中的每个字符只能在 ransomNote 中使用一次。 示例 1&#xff1a; 输入&#…...

从事人工智能学习Python还是学习C++?

人工智能&#xff08;Artificial Intelligence&#xff0c;简称AI&#xff09;是当今科技领域最热门的研究方向之一。AI 涉及多个学科和技术&#xff0c;特别是机器学习、神经网络、深度学习等技术的应用。在AI的开发过程中&#xff0c;编程语言的选择对于开发效率和项目实现至…...