Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Renaming the file
Name: gobi (by gp12) Date: May 10, 2007 at 23:18:37 Pacific OS: UNIX CPU/Ram: -/512
Comment:
hi, i am having set of files with the naming convention grap_Life_$cc$yy$mm$dd.txt. The above file was created by a script on this month.. i would like to get the above files to get renamed to today's date. i am encountering problem when there is two or more files with same format.. your help will be greatly appreciated. thanks for everyone
Name: ghostdog Date: May 13, 2007 at 05:24:17 Pacific
Reply:
what is $cc? and what do you mean by 2 or more files with same format? an example?
0
Response Number 2
Name: wollie Date: May 14, 2007 at 22:56:32 Pacific
Reply:
Hi ghostdog,
I tend to think that $cc represents the "century" - and the format: well, I guess that gobi refers to files with identical filenames when talking about "format". Well, several files with identical filename in the same directory ? no chance .
cheers
0
Response Number 3
Name: gobi (by gp12) Date: May 15, 2007 at 06:01:22 Pacific
Reply:
hi, i mean identical files in the same format but with different dates alone: eg: rush_Life_20070506.txt rush_Life_20070508.txt rush_Life_20070412.txt
I need to take only files for current month and rename them one by one to current date. hope u got my view.
thanks
gobi
0
Response Number 4
Name: ghostdog Date: May 15, 2007 at 20:58:47 Pacific
Reply:
if you don't mind, you can try this [code] month=`date '+%m'` current=`date '+%Y%m%d'` awk -v mth=$month -v cur=$current ' BEGIN{ FS="[.]"} { n=split($1,arr,"_") if ( substr(arr[3],5,2) == mth ){ arr[3] = cur result = arr[1] for (i = 2; i <= n; i++) result = result "_" arr[i] result=result"."$NF cmd = "mv " "\047" $0 "\047" " " "\047" result "\047" print cmd ## system(cmd) ##uncomment to execute
} }' "file" [/code]
0
Response Number 5
Name: gobi (by gp12) Date: May 17, 2007 at 19:56:53 Pacific
Reply:
hi, Thank u very much for ur help. it workssssss fineeeeee
Summary: I need help how to write the script rename the all the files "20060723" to "20060724" but all the name still be the same. Please help. Thanks NDCM_20060723_M06_ACTINICKERATOSIS_962.DAT.gz NDCM_2006...
Summary: I like to rename a file based on the first line. Here is an example of what I need to do. File: 034568.dat has 2000 lines with first line as HIOSPAD23409JHK90000 I like to extract 3 characters from 5t...
Summary: BTW, that doesn't rename the file...it creates a new empty file. Run these 2 commands (from the command line) to learn the difference. perldoc -f rename perldoc -f open ...