LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to move files in a loop? (https://www.linuxquestions.org/questions/programming-9/how-to-move-files-in-a-loop-724332/)

scofiled83 05-07-2009 02:50 AM

how to move files in a loop?
 
Hi


How can I move more than one files to new location?

Assume:

ls -lrt |more

-rw-rw---- 1 oracle dba 21906432 Feb 14 19:00 ab_0000001458_1.arc
-rw-rw---- 1 oracle dba 32099328 Feb 15 07:00 ab_0000001459_1.arc
-rw-rw---- 1 oracle dba 8423424 Feb 15 19:00 ab_0000001460_1.arc
...
...
...
-rw-rw---- 1 oracle dba 8423424 Feb 15 19:00 ab_0000001500_1.arc
...



I want to move the files between 1458 and 1500 to new location.
I tried this but didnt work.

for file in *{1458..1500}_*;
do
mv "$file" /ora/archives
done

chrism01 05-07-2009 03:37 AM

Basically like this
Code:

for num in `seq 1458 1500`
do
    mv ab_*${num}.arc /ora/archives
done


ghostdog74 05-07-2009 03:43 AM

Code:

mv ab_*{1458..1460}*arc /destination

colucix 05-07-2009 03:58 AM

Quote:

Originally Posted by scofiled83 (Post 3533010)
Code:

for file in *{1458..1500}_*;
do
  mv "$file" /ora/archives
done


This does not work because you put an extra underscore that does not appears in the file name (not in that position). The ghostdog's solution is more straightforward, anyway.

scofiled83 05-07-2009 04:02 AM

Hi
I tried it in current directory but error returned

mv ab_*{1450..1512}*arc /ora/archives

ab_*{1450..1512}*arc: cannot access: No such file or directory

ghostdog74 05-07-2009 04:05 AM

Quote:

Originally Posted by colucix (Post 3533075)
The ghostdog's

sed 's/The//' :)

ghostdog74 05-07-2009 04:06 AM

@OP, then in those sequences, some of them is missing in your file names. (my guess)

scofiled83 05-07-2009 04:10 AM

no
I just checked them,
I even tried for two file, still same error message.
Hp Unix

GazL 05-07-2009 04:18 AM

Quote:

Originally Posted by scofiled83 (Post 3533082)
Hi
I tried it in current directory but error returned

mv ab_*{1450..1512}*arc /ora/archives

ab_*{1450..1512}*arc: cannot access: No such file or directory

You can't use the wildcard at the beginning like that as it won't know where to stop matching characters Try something along the lines of

Code:

mv ab_000000{1450..1512}.arc /ora/archives

scofiled83 05-07-2009 04:26 AM

Again the same:

ab_*{1450..1452}*arc: cannot access: No such file or directory.

By the way:

ls -lrt

-rw-rw---- 1 oracle dba 1564672 Feb 12 20:42 ab_0000001451_1.arc
-rw-rw---- 1 oracle dba 1675264 Feb 12 23:24 ab_0000001452_1.arc
-rw-rw---- 1 oracle dba 28751872 Feb 13 07:00 ab_0000001453_1.arc
-rw-rw---- 1 oracle dba 75577344 Feb 13 19:01 ab_0000001454_1.arc
..
..
..
..
..
..

konsolebox 05-07-2009 05:01 AM

Are you using bash? And is brace expansion enabled as well as pathname expansion? What do you see when you do:

Code:

echo ab_000000????*.arc
?

GazL 05-07-2009 05:13 AM

Silently editing your original post to change the filenames you listed is a little on the disingenuous side. You've effectively made everyones responses to you look wrong, when based on the information you originally provided, they weren't. Making people who take the time to try and help you look stupid is bad form.

scofiled83 05-07-2009 05:28 AM

You are right Gazl
I appreciate your help.
I made a mistake.
then I correct it, I am truly sorry,
and
even it doesnt help, I appreciate your help

amysaraantony 05-07-2009 05:43 AM

I believe using SED is the need of the hour!
:)

Debian

colucix 05-07-2009 07:25 AM

Quote:

Originally Posted by konsolebox (Post 3533131)
Are you using bash? And is brace expansion enabled as well as pathname expansion?

@konsolebox, you hit the nail on the head.

@scofiled83, what is the output of
Code:

echo $-
this will tell you which options are set in the current shell. Also the "extended brace expansion" is a feature introduced in bash version 3. It does not work in older versions.


All times are GMT -5. The time now is 10:54 AM.