Results 1 to 5 of 5
filename is a list of absolute paths to files on individual lines
I want to use filename as input to /bin/mv:
mv `cat filename` destination/
Problem is there are whitespaces ...
- 06-28-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 2
file for input to /bin/mv
filename is a list of absolute paths to files on individual lines
I want to use filename as input to /bin/mv:
mv `cat filename` destination/
Problem is there are whitespaces in the pathnames. And if I escape the whitespaces
sed -E 's/\ /\\ '/g filename > filenameclean
mv `cat filenameclean` destination/
still fails (operating on paths with spaces as multiple arguements)
Any thoughts?
Thanks.
- 06-29-2007 #2Linux User
- Join Date
- Jun 2007
- Posts
- 318
Try enclosing filename in double quotes:
mv `cat "filename"` destination/
- 06-29-2007 #3Just Joined!
- Join Date
- Jun 2007
- Posts
- 3
have u tryed
"mv `cat filename` destination/"
or maybe
cat filename | mv destination
mv `cat filename` "destination"
one has to work
- 06-29-2007 #4
The problem here is that by using `cat filename`, you are printing out the file (spaces and all) to the commandline and then relying on Bash to parse them (and Bash breaks on spaces).
There are two ways to do this.
The first is using a loop to go through the file:
We read each line of filename, inserting each line into the 'mv' command.Code:exec 3< filename; while read line <&3; do mv "$line" destination/; done
The second way to do this is to use a program written for this purpose: xargs. The job of xargs is to read many lines and run the same command on each of them:
Here we redirect xargs's STDIN to be from filename, and let it essentially do the same thing as the loop above.Code:xargs -I{} mv "{}" destination/ < filename
Does this make sense?DISTRO=Arch
Registered Linux User #388732
- 06-29-2007 #5Just Joined!
- Join Date
- May 2007
- Posts
- 2


Reply With Quote
