For AWK and Bash, they use different string index systems. The first character of bash is recorded from 0; the first character of awk is recorded from 1; #012345678 ------------ Bash #123456789 ------------- The following is a case of Awk... for AWK and Bash, they use different string index systems. The first character of bash is recorded from 0; the first character of awk is recorded from 1; #012345678 ------------ Bash #123456789 --------------- The following is a case study of Awk: [html] [root @ Slave02 shell] # vi substring-extraction.sh #! /Bin/bash String = 23skidoo1 echo $ {String: 2: 4} echo | awk '{print substr ("'" $ {String} "'", 3,4 )} 'exit 0 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "Substring-extraction.sh" [New] 8L, using C written [root @ Slave02 shell] # sh substring-extraction.sh skid [root @ Slave02 shell] # use the prefix of the variable to match all the variables previously declared; for example: [html] [root @ Slave02 shell] # xyz23 = watever [root @ Slave02 shell] # xyz24 = asdf [root @ Slave02 shell] # echo "a =$ {! Xyz *} "a = xyz23 xyz24 [root @ Slave02 shell] # echo" a =$ {! Xyz @} "a = xyz23 xyz24 [root @ Slave02 shell] # throwing dice games; SPOTS = 6 ----- mod 6, the value range is 0-5die1 = 0die2 = 0 ------------. two variable names are available, make sure that the number Records selected for each plane are the same. let "die1 = $ RANDOM % $ SPOTS + 1" let "die2 = $ RANDOM % $ SPOTS + 1" let "throw = $ die1 + $ die2 "echo" Throw of the dice = $ throw "echo exit 0 verification results below: [html] Random number greater than 200 --- 25552 Throw of the dice = 5 [root @ Slave02 shell] # [html] random number less than 500 --- 0 Ra Ndom number greater than 200 --- 9765 Throw of the dice = 2 [root @ Slave02 shell] # [html] Random number greater than 200 --- 31180 Throw of the dice = 10 [root @ Slave02 shell] # [root @ Slave02 shell] # sh random2.sh Random number between 0 and 1 = 0.246062 [root @ Slave02 shell] # sh random2.sh Random number between 0 and 1 = 0.619153 [root @ slave02 shell] # sh random2.sh Random number between 0 and 1 = 0.619 153 [root @ Slave02 shell] # sh random2.sh Random number between 0 and 1 = 0.619153 [root @ Slave02 shell] # sh random2.sh Random number between 0 and 1 = 0.619153 [root @ Slave02 shell] # sh random2.sh Random number between 0 and 1 = 0.201116 [root @ Slave02 shell] # cat random2.sh #! /Bin/bash AWKSCRIPT = '{srand (); print rand ()} '-srand pseudo-Random calculation echo-n "Random number between 0 and 1 =" echo | awk "$ AWKSCRIPT" exit 0 [root @ Slave02 shell] #
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.