|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Copy files listed in a text file - whitespace problem.
Hi, Say I have this text file <copy.out> that contains a list of files/directories to be copied out to a different location. Code:
$ more copy.out dir1/file1 dir1/file2 dir1/file3 "dir1/white space" dir1/file4 If I do the following: Code:
$copy=`more copy.out` $echo $copy dir1/file1 dir1/file2 dir1/file3 "dir1/white space" dir1/file4 $cp -v $copy ./temp dir1/file4 -> ./temp/file4 cp: space": No such file or directory cp: "dir1/white: No such file or directory dir1/file3 -> ./temp/file3 dir1/file2 -> ./temp/file2 dir1/file1 -> ./temp/file1 All of the files managed to be copied except for the file with a whitespace. I have tried using for loop, but the same thing happened. Code:
$ copy=`while read line; do echo "$line"; done < copy.out` $ echo $copy dir1/file1 dir1/file2 dir1/file3 "dir1/white space" dir1/file4 $ cp -v $copy ./temp dir1/file4 -> ./temp/file4 cp: space": No such file or directory cp: "dir1/white: No such file or directory dir1/file3 -> ./temp/file3 dir1/file2 -> ./temp/file2 dir1/file1 -> ./temp/file1 I edited copy.out and replace "dir1/white space" with dir1/white\ space but it didn't work. Just by simply removing the double quotes failed to work either. I understand that by using echo, it will flatten any whitespace in $variable into a single space, so I've tried using double quotes $variable, but again, it failed to copy the file with a whitespace. I don't like whitespace in files/dirs name, but some people seem to like it, so I'd like to know how to fix this problem. Any advice offered is appreciated. Thanks. |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Code:
$ cat copy.out dir1/file1 dir1/file2 dir1/file3 dir1/white space dir1/file4 $ while read file;do echo cp "$file" ./Newdir;done <copy.out cp dir1/file1 ./Newdir cp dir1/file2 ./Newdir cp dir1/file3 ./Newdir cp dir1/white space ./Newdir cp dir1/file4 ./Newdir |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Code:
$ (IFS=$'\n"';cp -v $(<copy.out) dir2) `dir1/file1' -> `dir2/file1' `dir1/file2' -> `dir2/file2' `dir1/file3' -> `dir2/file3' `dir1/white space' -> `dir2/white space' `dir1/file4' -> `dir2/file4' |
|
#4
|
||||
|
||||
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
danmero, radoulov, cfajohnson:
All solutions worked ![]() Thank you so much! |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to search for text in a file and copy file | imeadows | UNIX for Dummies Questions & Answers | 9 | 11-12-2008 08:12 PM |
| How to copy a string to a text file | hpuxlxboy | UNIX for Advanced & Expert Users | 5 | 08-04-2008 12:59 AM |
| Copy text from a file from VI editor to Windows clipboard | zhshqzyc | UNIX for Dummies Questions & Answers | 13 | 08-07-2007 06:19 PM |
| CVSWeb - Directories listed but files not listed | ganesh | HP-UX | 0 | 09-16-2005 04:32 PM |
| Files listed Do not really exist | Ricky Raynor | UNIX for Advanced & Expert Users | 6 | 02-08-2002 04:20 PM |
|
|