f



Copy files using filenames from text files

How can I do this????

I have the file "lista.txt", and this file have the next information:
     one.txt
     two.txt
     five.txt
    six.txt
-------------------
This files exist in the same directory that "list.txt", I would like to
copy this files to other directory

Using Windows the batch file would be like this:  for /f "tokens=*" %i
in (list.txt) do copy "%i" destdir\

How can I do something like that in UNIX??

Best Regards

0
altariamx2003
11/19/2006 11:48:35 PM
comp.unix.shell 15484 articles. 3 followers. Post Follow

4 Replies
772 Views

Similar Articles

[PageSpeed] 25

altariamx2003@gmail.com ha escrito:

> How can I do this????
>
> I have the file "lista.txt", and this file have the next information:
>      one.txt
>      two.txt
>      five.txt
>     six.txt
> -------------------
> This files exist in the same directory that "list.txt", I would like to
> copy this files to other directory
>
> Using Windows the batch file would be like this:  for /f "tokens=*" %i
> in (list.txt) do copy "%i" destdir\
>
> How can I do something like that in UNIX??
>
> Best Regards

I would like to do this with shell script or bash script

0
altariamx2003
11/19/2006 11:52:21 PM
On 2006-11-19, altariamx2003@gmail.com wrote:
> How can I do this????
>
> I have the file "lista.txt", and this file have the next information:
>      one.txt
>      two.txt
>      five.txt
>     six.txt
> -------------------
> This files exist in the same directory that "list.txt", I would like to
> copy this files to other directory
>
> Using Windows the batch file would be like this:  for /f "tokens=*" %i
> in (list.txt) do copy "%i" destdir\
>
> How can I do something like that in UNIX??

other_directory=/path/to/other/directory
while IFS= read -r file
do
  cp "$file" "$other_directory"
done < lista.txt


    If you are sure that there are no spaces in the filenames, you can
    do:

cp `cat lista.txt` "$other_directory"

-- 
   Chris F.A. Johnson, author        <http://cfaj.freeshell.org/shell>
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   ===== My code in this post, if any, assumes the POSIX locale
   ===== and is released under the GNU General Public Licence
0
Chris
11/20/2006 2:01:31 AM
Another way might be:

destdir=/some/other/directory
for source in `cat lista.txt`
do
  cp $source $destdir
done

Keep in mind this is a quick and dirty script.  There is no error
checking going on - if there are files with the same name in your
destdir this for loop will overwrite it.  But you could you option to
cp to prompt if it will overwrite files (man cp).  You could also do
one of several file tests along with a continue statement to accomplish
the same thing.

You have to love the shell - there's (usually) more than one way to do
it!

Hope this helps,
Brian

Chris F.A. Johnson wrote:
> On 2006-11-19, altariamx2003@gmail.com wrote:
> > How can I do this????
> >
> > I have the file "lista.txt", and this file have the next information:
> >      one.txt
> >      two.txt
> >      five.txt
> >     six.txt
> > -------------------
> > This files exist in the same directory that "list.txt", I would like to
> > copy this files to other directory
> >
> > Using Windows the batch file would be like this:  for /f "tokens=*" %i
> > in (list.txt) do copy "%i" destdir\
> >
> > How can I do something like that in UNIX??
>
> other_directory=/path/to/other/directory
> while IFS= read -r file
> do
>   cp "$file" "$other_directory"
> done < lista.txt
>
>
>     If you are sure that there are no spaces in the filenames, you can
>     do:
>
> cp `cat lista.txt` "$other_directory"
>
> --
>    Chris F.A. Johnson, author        <http://cfaj.freeshell.org/shell>
>    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
>    ===== My code in this post, if any, assumes the POSIX locale
>    ===== and is released under the GNU General Public Licence

0
Brian
11/20/2006 11:54:59 AM
Brian Mac ha escrito:

> Another way might be:
>
> destdir=/some/other/directory
> for source in `cat lista.txt`
> do
>   cp $source $destdir
> done
>
> Keep in mind this is a quick and dirty script.  There is no error
> checking going on - if there are files with the same name in your
> destdir this for loop will overwrite it.  But you could you option to
> cp to prompt if it will overwrite files (man cp).  You could also do
> one of several file tests along with a continue statement to accomplish
> the same thing.
>
> You have to love the shell - there's (usually) more than one way to do
> it!
>
> Hope this helps,
> Brian
>
> Chris F.A. Johnson wrote:
> > On 2006-11-19, altariamx2003@gmail.com wrote:
> > > How can I do this????
> > >
> > > I have the file "lista.txt", and this file have the next information:
> > >      one.txt
> > >      two.txt
> > >      five.txt
> > >     six.txt
> > > -------------------
> > > This files exist in the same directory that "list.txt", I would like to
> > > copy this files to other directory
> > >
> > > Using Windows the batch file would be like this:  for /f "tokens=*" %i
> > > in (list.txt) do copy "%i" destdir\
> > >
> > > How can I do something like that in UNIX??
> >
> > other_directory=/path/to/other/directory
> > while IFS= read -r file
> > do
> >   cp "$file" "$other_directory"
> > done < lista.txt
> >
> >
> >     If you are sure that there are no spaces in the filenames, you can
> >     do:
> >
> > cp `cat lista.txt` "$other_directory"
> >
> > --
> >    Chris F.A. Johnson, author        <http://cfaj.freeshell.org/shell>
> >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> >    ===== My code in this post, if any, assumes the POSIX locale
> >    ===== and is released under the GNU General Public Licence

THANKS

0
altariamx2003
11/20/2006 5:26:29 PM
Reply: