required operation bash command example result
get substring in pipe cut -b first-last echo "123456789" | cut -b 1-6 123456
substring from variable ariable2=${variable1:start:num_of_chars} a="123456789"; b=${a:2:5}; echo $b 34567
length of the string – from variable variable2=${#variable1} 123456789; echo ${#a} 9
show characters in script as hexadecimal numbers echo "$mystring"|od -t x1 -c echo 'text 01'|od -t x1 -c
0000000  74  65  78  74  20  30  31  0a
          t   e   x   t       0   1  \n
0000010
show characters in script as decimal numbers echo "$mystring"|od -t x1 -c echo 'text 01'|od -t d1 -c
0000000  116  101  120  116   32   48   49   10
           t    e    x    t         0    1   \n
0000010
convert string to lower case echo "SoMeStriNg" | tr '[:upper:]' '[:lower:]'
replace more spaces with one echo "xxx zzz"|tr -s ' ' xxx zzz
trim spaces from beginning and end echo " xxx "|tr -d '[[:space:]]' xxx
store in variable string having multiple lines
variable=$(cat <<-EOF
here
is
some text
EOF
)