mv each file with a prefix 1 2 3 ....????
So lets say I have 3 files with very long names and I want to move them using a for loop....(or other options if it works):
#files in $DIREC: #fasdfalsdfjas;dlkfjasldkfjasdlfkjs.dcm #fasdfasfaifjre398r3948fjvdsf .dcm #f430f8uf0vjdsofvdoivjw048jvdfk.dcm #THIS IS THE CODE I AM THINKING ABOUT... for FILE in $( ls $DIREC*.dcm ); do mv $FILE ~/myname.dcm done ############## #BUT THIS WILL OVERWRITE EACH FILE...I want my output to look like this: #OUTPUT: ~/myname1.dcm ~/myname2.dcm ~/myname3.dcm #THIS IS DIFFICULT BECAUSE: 1. $DIREC could have more than 3 files. 2. names have no contast letters 3. I dont know how to use arrays in bash... PLEASE HELP ME! |
Code:
i=0;for FILE in $DIREC*.dcm |
Could you explain each coding you've done ? Also, could I get not prefix if there is only one single file?
|
i put comments in the code below:
Quote:
|
Also note a key difference between the for loop you proposed and the one schneidz used:
Code:
for FILE in $(ls $DIREC*.dcm) Code:
for FILE in $DIREC*.dcm |
See here for an explanation of the above:
Don't Read Lines With For Also, there's rarely any need for expr in modern shells. Integer math, at least, is available built-in. In addition, bash's version of printf can directly set a variable. Code:
i=1 |
Thanks for the note!
I'll give it a try....specially in the am if statement. |
anyways I can change numbers 1 2 3 4... for letters a b c d...?
|
Not directly, since the above is relies on mathematic incrementing. You'd have to do something like set up an array to substitute letters for numbers, or mess with ascii value incrementing or something like that.
But unfortunately I have to sign off now, so I won't be able to post anything for a while. Maybe someone else can post something. |
All times are GMT -5. The time now is 09:31 PM. |