在我的脚本中,我只需要保留字符串中的特定字符。 例如:
string="aPRO100z"
如何获得以下结果?
result="PRO100"
感谢您提供任何帮助。
答案 0 :(得分:2)
您可以使用sed
命令:
# in this example, we keep only the chars 0-9 and A-Z
result=`echo $string | sed 's/[^0-9A-Z]*//g'`;
答案 1 :(得分:0)
使用cut
:
result=$(echo ${string} | cut -c 2-7)