Thursday 15 March 2012

Get only the Filename using a Shell Script -



Get only the Filename using a Shell Script -

i'm trying illustration working:

here i'm trying do:

a) there 7 files in folder name , timestamp appended.

examples : windows_<timestamp>.csv , linux_<timestamp>.csv on , forth.

i want first a) move files i'm re-name new folder , rename current file.

i've tried looking @ rename multiple files replacing particular pattern in filenames using shell script script isn't working me. believe have modify in there, cant seem work.

can please help me? i'm stuck here.

thanks!

#!/bin/bash # find files created today , end extension. # a) first find files created today, , filter files care about. # b) move these files new folder. # c) iterate files in new folder. # d) re-name files in destination folder replacing _ sourcefoldername="/home/abhididdigi/desktop/taddm" targetfoldername="/home/abhididdigi/desktop/taddm_servicenow/" #find files created today , csv ones. find $sourcefoldername -type f -mtime 0 -name '*.csv'| while read filename # todo: find files care cp $filename $targetfoldername done #targetfilename=${filename%_*}|sed 's#.*/##'; #rename files now, removing timestamp underscore, ready consume. filename in $targetfoldername*; mv -v "${filename}" ${filename%_*}.`echo "${filename}" | awk -f. '{print $2}'` done

shell

No comments:

Post a Comment