Bash/korn Script Rename files to Same name one at a time
Hello all,
I have a question I hope someone can help me with, I have scowered the internet for the answer to this one. I need a script to rename multiple files to the same exact name, run a program on the file then do the same for the next file. We have a unix backend system that is expecting to load the file with the filename of cards.in So I will have files named card.2009xxx, like i said i will have around 4 or five of those. I want the script to rename card.2009xxx to cards.in, run our unix program on cards.in which inturn changes the file name and once complete i want the script to rename the next cards.2009 to "cards.in" Until there are no more left in the directory and the unix program has processed all the files. All of this is occurring in the same directory. I have written some scripts but they fail by moving for example cards.200901 to cards.in then immediately moving cards.200902 to cards.in and that is not good because it is overwriting valuable data. Any Help at all with this one is GREATLY appreciated. Thanks in advance. Tha |
Quote:
Please clarify about this: if all of these files ARE in the same directory, then each successive recursion of this process will overwrite the results of the last recursion. EDIT: I get it: the UNIX program will change the name from cards.in to some other name; THEN the process repeats. what you need is basically: 1 ) rename the file to cards.in 2 ) call the UNIX program to edit the file and rename it something else. 3 ) Find the next file, repeat step 1. right? Sasha |
Quote:
kernelzack$ ls cards.200901 cards.200902 cards.200903 What I want to do is have my script change cards.200901 into cards.in then call the unix program. Once the unix program is called it will process the contents of cards.in and change the file name too cards.in200901 As soon as that process completes i would like the script to move cards.200902 to cards.in and call the unix program, and so on until the unix program has been run on all three files. So is there a way to do that with a loop of some sort? Thanks again. |
You got it!
|
Yep, a loop, and a simple one at that.
There are surely lots of ways to go about this; I'll point you towards one way: Code:
ALWAYS have a backup! Cheers, Sasha |
update - it isn't working right.. play with it a bit. when/if I fix it, I'll post a fix.
|
Quote:
No worries, I really appreciate you working on this with me. I will keep playing around with the code and if I can get it to work I will post what was done. Thanks! |
Possibly better option, adapted from GrapefruiTgirl's script:
Code:
#!/bin/sh |
@ H_TeXMeX_H,
THANK YOU! For whatever reason, I kept picking up the newline in the list of filenames and was having a ridiculous time with that simple Gawk. @ the OP - has this modification helped, e.i. is it working now? Cheers, Sasha |
Thank you both!!, I really appreciate all the help. During my first round of tests (calling a test program) it seems to work great. I will run our actual program and let you know how it goes, after testing I see no reason why it wouldn't work. I will update you either way, thanks again!!
|
Also, depending on your circumstances you can change:
for filename in cards.?????? to for filename in cards.2009* The '?' matches any one character, the '*' matches any number of characters, so you decide what is appropriate. |
All times are GMT -5. The time now is 12:26 AM. |