#!/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