-
Shell - convert a character to ASCII code and vice versa
摘要:scnzzh@ZUBT:~$ printf %d "A" bash: printf: A: invalid number 0scnzzh@ZUBT:~$ printf %d "'A" 65scnzzh@ZUBT:~$ printf "\\$(printf %o 65)" Ascnzzh@ZUBT:~
阅读全文
-
Shell - seq
摘要:scnzzh@ZUBT:~$ seq 65 906566676869707172737475767778798081828384858687888990
阅读全文
-
Shell - length of string
摘要:scnzzh@ZUBT:~$ echo abc | wc -m 4 abcscnzzh@ZUBT:~$ echo -n 'abc' | wc -m 3 -m, --chars print the character counts
阅读全文
-
Shell - uppercase to lowercase and lowercase to uppercase
摘要:scnzzh@ZUBT:~$ echo 'abc123' | tr '[:lower:]' '[:upper:]' ABC123 scnzzh@ZUBT:~$ echo 'ABC123' | tr '[:upper:]' '[:lower:]' abc123 $ tr '[:upper:]' '[:
阅读全文
-
Sed - search, print, replace
摘要:Search and print matched lines: scnzzh@ZUBT1:~/zzh$ sed -n '/ExecStart/p' docker.service ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/contain
阅读全文
-
bash - ERROR: binary operator expected
摘要:scnzzh@ZUBT:~$ re='^[0-9]+$' scnzzh@ZUBT:~$ a=001 scnzzh@ZUBT:~$ b=a12 scnzzh@ZUBT:~$ if [ $a =~ $re ]; then echo 'yyy'; fi bash: [: =~: binary operat
阅读全文
-
Shell - grep: Invalid regular expression
摘要:scnzzh@ZUBT:~$ echo '[abc]' | grep '[' grep: Invalid regular expression scnzzh@ZUBT:~$ echo '[abc]' | grep '\[' [abc] scnzzh@ZUBT:~$ echo '[abc]' | gr
阅读全文
-
awk - print only matched field
摘要:awk '/regexp/{for(i=1;i<=NF;++i)if($i~/regexp/)print $i}' /path/to/inputfile scnzzh@ZUBT:~$ echo 'a=1 b=2' | awk '/a=/{for(i=1;i<=NF;++i)if($i~/a=/)pr
阅读全文
-
Shell - automatically trim
摘要:zzh@ZZHPC:~$ a=" aaa aaa " zzh@ZZHPC:~$ echo "$a" aaa aaa zzh@ZZHPC:~$ echo $a aaa aaa zzh@ZZHPC:~$ b="bbb${a}bbb" zzh@ZZHPC:~$ echo "$b" bbb aaa aaa
阅读全文
-
Shell - substr
摘要:$>expr substr 'abcdefg' 1 3 abc zzh@ZZHPC:~$ a=123456789 zzh@ZZHPC:~$ echo ${a:2} 3456789 zzh@ZZHPC:~$ echo ${a:3:3} 456 zzh@ZZHPC:~$ echo ${a:3:${#a}
阅读全文
-
Shell - index
摘要:$>expr index 'abcdef' 'b'2 $>expr index 'abcdef' 'be'2 $>expr index 'abcdef' 'ca'1 $>expr index 'abcdef' 'dq'4 $>expr index 'abcdef' '12'0 #index stri
阅读全文
-
Shell - eval
摘要:zzh@ZUBT:~$ echo 'aaa123' > zzh.txt zzh@ZUBT:~$ echo 'aaa456' >> zzh.txt zzh@ZUBT:~$ cmd='grep aaa zzh.txt | grep 123' zzh@ZUBT:~$ eval $cmd aaa123
阅读全文
-
Shell - OR, AND condition
摘要:zzh@ZZHPC:~$ if [ 1 -lt 0 -o 1 -gt 0 ]; then echo "yyy"; else echo "nnn"; fi yyy zzh@ZZHPC:~$ if [ 1 -lt 2 -a 1 -gt 0 ]; then echo "yyy"; else echo "n
阅读全文
-
awk
摘要:zzh@ZUBT:~$ echo ansible_host=10.0.2.5 | awk -F'=' '{print $2}' 10.0.2.5 scnzzh@ZUBT:~$ echo 'abaca' | awk -F'[bc]' '{print $1 $2 $3}' aaa scnzzh@ZUBT
阅读全文
-
Linux - tar
摘要:List files in tar file: tar -tf filename.tar.gz tar -tvf filename.tar.gz Create tar.gz file: zzh@ZUBT:~$ tar -czvf aaa.tar.gz aaa aaa/ aaa/a.txt Extra
阅读全文
|