SHELL learning transcript

Source: Internet
Author: User
SHELL learning transcript I learned shell some time ago and made some notes. I hope it will be helpful to some scholars as follows: 1. echo & quot; hello & quot; output hello, automatically print line feed echo & quot; hello \ c & quot; however, echo does not print line feed echo * show all files, not including hiding...
SHELL learning transcript I learned shell some time ago and made some notes. I hope it will be helpful to some scholars as follows: 1. echo "hello" outputs hello and automatically prints the line break echo "hello \ c". However, echo does not print the line break echo * displays all files, excluding hidden file echo. * show hidden files. 2. printf format-string [arguments] almost implements the printf function in C. It is not like echo's automatic line feed 3. redirection <change standard input program <file change standard input of program to file> change standard output program> file change standard output of program to file when the target file does not exist, a new file is created, if a file exists, it overwrites the program> file and appends the content to the end of the file. the parameter uses: The Nth parameter of www.2cto.com $ n (and The macro of is similar. $ n is a simple alternative. $ n $ m can be combined into a parameter. the variable value "=" cannot contain spaces. 5. wildcard: * matches multiple characters? Match a character [charset] to match the character in charset. for example, [0123456789] to match a number 0123456789, you can also write it as [0-9] [! Charset] use the complement set of charset as the matching set. 6. variable replacement: $ {parameter:-word} if parameter is empty or not set, use word instead of parameter. the parameter value remains unchanged $ {parameter: = word} if parameter is null or not set, the parameter is set to the value word $ {parameter :? Message} if parameter is empty or not set, the message is output as a standard error $ {parameter: + word}. if parameter is set, replace it with word instead of parameter, parameter value unchanged 7. reference: disables the special meaning of a character \ ''" 8. if list1 ------------> when the exit code of list1 is 0, it is true then list2 elif list3 then list4 else then list5 fi test expression = [expression] expression is the expression that can be understood by test: -file test: Check whether the file meets certain special rules: test option file option such as vcHRpb24 = "src =" http://up.2cto.com/2012/0804/20120804092355557.gif "/>-String comparison:-z string length is 0 true-n string length is not 0 true string1 = string2 string1! = Sting2-number comparison: integer comparison int1 option int2 option ---->-eq,-ne,-lt,-le,-gt,-ge =! = <=> =-Compound expression :! Non-a and st if [expression1-a expression2]-o or 9. case word in pattern1) list1; pattern2) list2 ;;... www.2cto.com esac 10. while command ------> 0 is true do list done 11. until command do list done 12. the array subscript uses numbers. Auto-increment should be like this: index = $ (expr $ index + 1), expr is indispensable, and space on both sides of "+" must be applied to the element values in the array, this should be the case: $ {array [$ index]}, curly brackets should not be used to list all elements in the array: echo $ {arrar [*]} 13. character processing truncation: expr substr "$ var" 1 2 truncates the two characters var2 = · expr substr of the variable var from the first character "$ Var" 1 2. assign the intercepted characters to the variable www.2cto.com ==================== ================= AWK ==================================== =======================================1. awk program: mode + operation pattern {action} pattern default: action application in each input record action default: print matching record to standard output 2 special pattern: BEGIN: the associated operation is executed only once. before any command line file or common command line assignment is processed, The-v option at the beginning is specified to be completed. it is mostly used to initialize the END: the associated operation is executed only once. after all input data is processed, the summary report is generated or cleared. common built-in variables: ARGC parameter count ARGV parameter vectors or parameter values FILENAME Name of the current input file FNR number of records of the current input file FS field delimiter (regular expression, default: "") number of fields of the current NF record NR at work (job) number of records in the OFS output field delimiter. the default delimiter is "" ORS output records, and the default delimiter is "\ n" 3. array variable: subscript can be any number or string expression, not necessarily an integer 4. command line parameters: 5. record: A blank row can also be a record ========================================== ======================================================= ======================== 1. sed calls sed [option] sed command input file sed [option]-f sed script file input file sed script file [option] input file option: www.2cto.com-n do not print edit line-p print-c next command Is used to edit the command-f to execute the sed script. when the address sed is used to browse the input file, it starts from the first line by default. you can locate the text as follows: 1 ). use row number: n rows n, m rows n-m rows (including rows m) n, m! The row 1 of the n and m parts of the row number, $ the first row-the last row 2 ). use a regular expression:/pattern/rows in the contain mode/pattern1/pattern2/contains rows in two modes pattern/, n specifies rows in the contain mode n,/pattern /?? 3. sed Edit command: p print matching row = display row number a \ add information after locating row number I \ insert information after locating row number d delete locating row c \ replace s pattern match replace r from another file read text w write text to file q exit l display control character {} n g Global y n ^ line start instance: sed '/sdd/=' test.txt prints all content of test.txt, and display the row number sed-n-e '/sdd/p'-e'/sdd/= 'test.txt that matches the 'sdd'. only the matching row is printed and the row number is displayed, neither of them can be less than www.2cto.com 4. insert text 5. modify text format: [address [, address] c \ text function: replace the positioning line with the text format: [address [, address] I \ text function: insert the row text format before the row to be located: [address [, address] a \ text function: append the row text 6 after the row is located. delete text format: [address [, address] d function: Delete Location line 7. replace text format: [address [, address] s/pattern_to_find/replacement_pattern/[g p w n] function: g: by default, it replaces the first pattern match, g can be used for global pattern matching. p: by default, all replace rows are printed. p can invalidate the-n option. w: write to the specified file. n: &: indicates the original mode instance: sed-n's/aaa/ccc &/p' test.txt mode append ccc sed-n's/aaa/& ccc/p' test.txt mode aaa and then append ccc 8. read/Write file www.2cto.com format: [address [, address] w filename function: write the location row to the file filename format: address r filename function: append the file filename to the instance after the row is located: sed '/^ $/d' filename delete empty row sed's/^ [0-9] // g' filename remove first row number author Wowo (Big Me)
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.