如果我有一个格式为 的文件./AAAA_AAAA_00_00_AAA-22222.txt
,我如何才能将其拆分为AAAA_AAAA_00_00_AAA
和22222
?
答案1
$ filename=./AAAA_AAAA_00_00_AAA-22222.log
$ filename=$(basename "$filename" .log) # remove `./` and `.log`
$ echo "${filename}"
AAAA_AAAA_00_00_AAA-22222
$ echo "${filename%%-*}"
AAAA_AAAA_00_00_AAA
$ echo "${filename##*-}"
22222
${parameter##word}
删除最长的前缀模式${parameter%%word}
删除最长的后缀模式
看Shell 参数扩展(bash手册)