hello peoples, Assume a file containing a list of filenames. $cat list ein langer sommerabend.txt some other file Now, I want to copy them all at once and write therefor a loop like this $for i in $(cat list); do cp $i newdir; done Obviuosly I am running into the "whitespace in a filename" problem which I don't know how to solve. Does have somebody an advice or a working solution for me? Best regards, Daniel
Enclose the $i in double quotes and you don´t have the problem anymore.
Chris S. schrieb:
> Enclose the $i in double quotes and you don´t have the problem anymore.
Won't help because the input is already split into separate words by the
"for i in $(cat list)".
(while read i; do cp "$i" newdir; done) <list
Then use the command apply, or use sed instead. Apply is more simple and useful, check the man page. sed would be something like this, remove the echo after testing. sed -e 's/^[ \t]*/echo cp "/' -e 's,[ \t]*$," newdir,' list |sh
Chris S. schrieb: > Then use the command apply, or use sed instead. > Apply is more simple and useful, check the man page. > > sed would be something like this, remove the echo after testing. > > sed -e 's/^[ \t]*/echo cp "/' -e 's,[ \t]*$," newdir,' list |sh Should this have any advantage over my solution?
You have to set the InternalFieldSeperator-Variable to the newline char. Then bash will cut the input in lines, instead of token. http://wi-fizzle.com/article/276
[offtopic] Usefull for filetransfers Windows <=> Linux... detox http://detox.sourceforge.net/ [/offtopic]
cat list | while read FILE; do cp "$FILE" newdir; done
Thank you. (while read i; do cp "$i" newdir; done) <list this one I like the most
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.