【发布时间】:2021-04-13 16:13:57
【问题描述】:
我在 mydir 中有这些文件:
APPLE_STORE_iphone12.csv
APPLE_STORE_iphonex.csv
APPLE_STORE_ipad.csv
APPLE_STORE_imac.csv
需要在匹配模式“APPLE_STORE_”之后重命名文件。
必需的 O/P
APPLE_STORE_NY_iphone12_20210107140443.csv
APPLE_STORE_NY_iphonex_20210107140443.csv
APPLE_STORE_NY_ipad_20210107140443.csv
APPLE_STORE_NY_imac_20210107140443.csv
这是我尝试过的:
filelist=/mydir/APPLE_STORE_*.csv
dtstamp=`date +%Y%m%d%H%M%S`
location='NY'
for file in ${filelist}
do
filebase=${file%.csv}
mv ${file} ${filebase}_${location}_${dtstamp}.csv
done
这是给我的名字,如 APPLE_STORE_imac_NY_20210107140443.csv
【问题讨论】: