$ i=5;j=9423483247234;$ echo $i | grep -q "^[0-9]$"$ echo $?0$ echo $j | grep -q "^[0-9]+$" $ echo $?0
$ c="A"; d="fwefewjuew"; e="fewfEFWefwefe"$ echo $c | grep -q "^[AZ]$"$ echo $d | grep -q "^[az]+$" $ echo $e | grep -q "^[a-zA-Z]+$"
$ ic="432fwfwefeFWEwefwef"$ echo $ic | grep -q "^[0-9a-zA-Z]+$"
$ echo " " | grep " "$ echo -e "t" | grep "[[:space:]]" #[[:space:]] will match both spaces and TAB keys $ echo -e " t" | grep "[[:space:]]"$ echo -e "t" | grep "" #To press the TAB key on the keyboard, not the character
$ echo "[email protected]" | grep "[0-9a-zA-Z.]*@[0-9a-zA-Z.]"[email protected]
$ echo "http://news.lzu.edu.cn/article.jsp?newsid=10135" | grep "^http://[0-9a-zA-Z./=?]+$"http ://news.lzu.edu.cn/article.jsp?newsid=10135
illustrate:
/dev/nulland
/dev/zeroThe equipment is very interesting. It is like a black hole. Anything that falls into it will disappear. The latter is also an energy box, and you can always get 0 from there until you exit.
[[:space:]]yes
grepMarker used to match spaces or TAB key characters. Please check the help for other markers:
man grep
All of the above are used
grepto perform pattern matching, in fact
sed,
awkBoth can be used for pattern matching. For knowledge about regular expressions used in matching, please refer to the relevant information below.
If you want to determine whether a string is empty, you can determine whether its length is zero. You can use
testcommanding
-zoptions to implement, see the specific usage
testOrder,
man test
$ echo "tn" | grep "[[:print:]]"tn$ echo $?0$ echo -e "tn" | grep "[[:print:]]"$ echo $?1
In addition to the character types that make up a string, what other properties does a string have? The number of characters that make up the string.
Next we will calculate the length of a string, that is, the number of all characters, and briefly introduce several methods for finding the number of specified characters in a string.
That is to count the number of all characters, there are various calculation methods, choose the best one and use it:
$ var="get the length of me"$ echo ${var} # This is equivalent to $varget the length of me$ echo ${#var}20$ expr length "$var"20$ echo $var | awk '{ printf("%dn", length($0));}'20$ echo -n $var | wc -c20
$ echo $var | tr -cd g | wc -c2$ echo -n $var | sed -e 's/[^g]//g' | wc -c2$ echo -n $var | sed -e 's /[^gt]//g' | wc -c5
For more related information, see the word statistics related examples in "Numerical Computation".
$ echo $var | wc -w5$ echo "$var" | tr " " "n" | grep get | uniq -c1$ echo "$var" | tr " " "n" | grep get | wc -l1
illustrate:
${}Operators are a "big name" in Bash and are capable of quite a lot of tasks. For details, see "Thirteen Questions about Shell" written by someone on the Internet.
$(())and
$()besides
${}What's the difference? "Bar.
Next, we discuss how to control the display of characters in the terminal.
$ echo -e "