Linux: whitespace im Dateinamen: Wie kann ich das lösen?

Gast #1427029
Lesenswert?

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
#1427077
Lesenswert?

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?

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren