Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to make copy with filelist on Linux?

Status
Not open for further replies.

klug

Advanced Member level 1
Advanced Member level 1
Joined
Jul 4, 2002
Messages
474
Helped
12
Reputation
24
Reaction score
7
Trophy points
1,298
Activity points
4,356
linux copy filelist

Some problem:

I have some dir with files on it. Also I have some file with list of files to copy. How to copy only files from that list?

I have made some bash script:
-------------------------
#!/bin/bash
#
#

SORCEDIR=/home/danny/files/
TARGETDIR=/home/danny/files2/
ALIST=/home/danny/filelist.txt

FILELIST=`cat $ALIST`

for NAME in $FILELIST

do

cp $SORCEDIR$NAME $TARGETDIR

done
------------------------

But this script is not working correctly if file name has space on it (for example "Last Doc.pdf" ) . How to make correct script?

Thanks in advance. klug.
 

You are getting to compicated to do that. cp recives arbitrary archives space separated and the last argument its recieves its the target.

cp file_1_ext file_2.ext ... filen_ext target_dir/


And the space thing on *nix is trated as a special carater so you need to precede it with a \ , I reccomend avoid using spaces in names and replacing with _ cuz if you work often in *sh you will see that you are getting 2 caracters more to type, even with TAB...
does de work....

I assume you can guess the rest... :D
 

Yes, I know that it is better to avoid spaces in filenames, but I have this problem and I cannot change filenames and list.

I have solved this problem by this way:

-------------------------
#!/bin/bash
#
#

SORCEDIR=/home/danny/files/
TARGETDIR=/home/danny/files2/
ALIST=/home/danny/filelist.txt

cd $SORCEDIR
tar cvf - --files-from $ALIST | (cd $TARGETDIR ; tar xvf -)
------------------------
 

HAHAHAH goood way to do that, still itsn't the BEST way, maybe you could use a filter.
(It's from mysql, but yoy can use it)

replace \\b \\\ -- filelist.txt

\b is a switch that replace needs to find spaces the aditional \ is the well known reason, maybe you could place a \(space) here, I'm not sure
\\ puts a \ in the file
and the \ (space) puts the space in the file. that's why the \\\(space)

It does the work of translating the spaces

There's a even better way to do that, is a pipe that translates on the fly, but I don't remember quite well, so I'm not messing with it right now
 

Thanks, deepspawn,

I also was looking for replacing " ", but have not found the way... There is no "replace" command in my Slackware Linux. :(
Anyway, thanks for your idea, I will keep it for the future ;)

Best Wishes! klug.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top