#!/bin/bash
# find all the files that are created today and end with an extension.
# a) First find all the files created today, and filter only the files we care about.
# b) Move all these files into a new folder.
# c) Iterate all the files in this new folder.
# d) Re-name all the files in the destination folder by replacing the _
sourceFolderName="/home/abhididdigi/Desktop/TADDM"
targetFolderName="/home/abhididdigi/Desktop/TADDM_ServiceNow/"
#find all the files created today and only the CSV ones.
find $sourceFolderName -type f -mtime 0 -name '*.csv'|
while read filename
do
# TODO: Find only those files that we care about
cp $filename $targetFolderName
done
#targetFileName=${filename%_*}|sed 's#.*/##';
#Rename the files now, removing the timestamp from underscore, so that it is ready to consume.
for filename in $targetFolderName*; do
mv -v "${filename}" ${filename%_*}.`echo "${filename}" | awk -F. '{print $2}'`
done
为了这个工作,我将不得不先遍历目录中的所有文件。下面是我使用这样做 '#!/斌/庆典 FILES = /家庭/ abhididdigi /桌面/ $中FILES TADDM/* 为f执行 回声“处理$ F文件中的脚本...“ #对每个文件执行操作。 $ f存储当前文件名 cat $ f done' 我被困在这里。这不会给我一个文件名作为输出,这给了我整个文件夹路径。一旦我得到这个工作,计划是注入上述链接中的代码,并使其工作。 – abhididdigi 2014-11-03 15:04:52
将'for'换成'for home/abhididdigi/Desktop/TADDM/* do' – nu11p01n73R 2014-11-03 15:12:42
我试过了,它给了我'做'不是一个文件。 #!/斌/庆典 在家庭/ abhididdigi /桌面/ TADDM F/*做 做 回声 “处理$ F文件...” #采取每个文件的行动。 $ f store当前文件名 cat $ f done 我得到了:cat:home/abhididdigi/Desktop/TADDM/*:没有这样的文件或目录 – abhididdigi 2014-11-03 15:21:15