${parameter#word}
${parameter##word}
Remove matching prefix pattern. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted.
${parameter%word}
${parameter%%word}
Remove matching suffix pattern. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted.
Below bash script explains the concepts of find and cut the string within the string, feel free to copy and use this script.
Continue Reading...
${parameter##word}
Remove matching prefix pattern. If the pattern matches the beginning of the value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``#'' case) or the longest matching pattern (the ``##'' case) deleted.
${parameter%word}
${parameter%%word}
Remove matching suffix pattern. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern (the ``%'' case) or the longest matching pattern (the ``%%'' case) deleted.
Below bash script explains the concepts of find and cut the string within the string, feel free to copy and use this script.
Source: cat string_cut.sh
#!/bin/bash
var="Linuxpoison.Linuxpoison.Linuxpoison"
echo
echo -e "Value of var is: $var"
echo "--------------------------------------------"
echo 'Find all *nux from the start of the string and cut ${var##*nux} :'
echo ${var##*nux}
echo "-------------------------------------------"
echo 'Find the first *nux from the start of the string and cut ${var#*nux} :'
echo ${var#*nux}
echo "-------------------------------------------"
echo 'Find all .* from the back of the string and cut ${var%%.*} :'
echo ${var%%.*}
echo "------------------------------------------"
echo 'Find first .* from the back of the string and cut ${var%.*} :'
echo ${var%.*}
#!/bin/bash
var="Linuxpoison.Linuxpoison.Linuxpoison"
echo
echo -e "Value of var is: $var"
echo "--------------------------------------------"
echo 'Find all *nux from the start of the string and cut ${var##*nux} :'
echo ${var##*nux}
echo "-------------------------------------------"
echo 'Find the first *nux from the start of the string and cut ${var#*nux} :'
echo ${var#*nux}
echo "-------------------------------------------"
echo 'Find all .* from the back of the string and cut ${var%%.*} :'
echo ${var%%.*}
echo "------------------------------------------"
echo 'Find first .* from the back of the string and cut ${var%.*} :'
echo ${var%.*}
0 comments:
Post a Comment