我有几个文件的名称为:
ID_Italy.txt
ID2_USA.txt
ID3_Germany.txt
.....
如果我想在 _ 之前打印,我可以:
for file in *.txt; do print "${file%_*}";done
输出:
ID
ID2
ID3
如果我想打印并删除扩展名:
for file in *.txt; do print "${file%.*}";done
输出:
ID_Italy
ID2_USA
ID3_Germany
但是,我只想取介于 _ 和 . 并具有以下输出:
Italy
USA
Germany
那怎么打印?