bash for loop to copy files
I want to copy job-5, job-6, job-7..... to LA-1, LA-2 LA-3 ...
My command is : for subdir in LA-*; do (cd "$subdir"; cp -r /scratch/job-$(i+4) .); done But linux is not taking this command, can i do it in other ways? Thanks |
well you've not defined a few things there. just putting LA-* doesn't invoke a filesystem command for starters so you'll need define it. I'm about to go to bed so can't give you a full answer but your first part will be more like:
for subdir in $(ls -l |awk '{print $9}' |grep LA); do...etc Also you're pulling a command i+4 which doesn't make any sense in that context. If I had time I'd tell you the rest but my bed is calling me. |
I think my questions was not clear. I have folders named job-5 to job-7 and they are running in scratch directory. after the job is finished i want to copy them in folders named LA-1 to LA-4. Actually my main question was can i use $(i+4) for file name? If it was job-1 to job-4 and i had to copy them to LA-1 to LA-4, there was no problem, my above command can do that easily:for subdir in LA-*; do (cd "$subdir"; cp -r /scratch/job-$i .); done
|
Hi,
does the following do what you want? Code:
for i in {1..9} ; do j=$((i+4)) ; echo cp -r /scrach/job-$j LA-$i; done Cheers, Evo2. PS. Remove the "echo" to actually make it work. |
Thanks, i think that would do the job. At first i tried two loops using i and j but than i realized that would be a mess. thanks for the idea.
|
How about:
Code:
cd scratch Regards, Stefan Oops, Evo2 beat me to it. |
All times are GMT -5. The time now is 12:03 PM. |