copying files with dumb characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting copying files with dumb characters
# 1  
Old 06-17-2008
copying files with dumb characters

hello
I'm trying to batch copy files from one location to another. My script get's the output of a find command (i.e. find /disk3/jpm/seq -type f | xargs copy2boss)
The script works fine, except when filenames contains whitespace, backslashes and so on. Any hints? Is there another more accurate approach?

I need to copy files from user's seq directory to the boss's seq folder. The destination folder depends on the source folder.
Example copy
/disk3/user1/seq/tah/file1
to
/disk3/boss/seq/tah/file1


Here's the copy2boss script (sorry for the tcsh Smilie)
Code:
@ loop = 0
while ( $loop < $# )
    @ loop ++
    set current_file = $argv[$loop]
    set target = (`echo $current_file | sed 's:\(\/disk3\/\).*\(\/seq\/\):\1boss\2:'`)
    set target_dir = (`echo $target | sed 's|\(.*/\).*|\1|'`)
    if ( ! -d $target_dir ) then
        mkdir $target_dir
        chown boss:user $target_dir
    endif
    if ( ! -r $target ) then
        cp -p $current_file $target
        chown boss:user $target 
    endif
end

best regards
# 2  
Old 06-17-2008
Try enclosing all the sensible variables into double quotes, like this:

Code:
cp -p "$current_file" "$target"

# 3  
Old 06-18-2008
thank you for the answer
I tried it but doesn't work. The problem comes probably from the fact that I'm a newbie and didn't choose the right method.

What I found out is that I should enclose the find output with quotes before passing it to the script. This way nothing (hopefully) get interpreted.

Code:
find /disk3/omar/seq/plasmids/ -type f | sed "s/.*/\'&\'/" | xargs copy2boss

And I also did follow your suggestion as this
Code:
#!/usr/bin/tcsh 
##
#
#
@ loop = 0
while ( $loop < $# )
    @ loop ++
    set filename   = `basename "$argv[$loop]"`
    set source_dir = `dirname "$argv[$loop]"`
    set target_dir = `echo "$source_dir" | sed 's/\(\/disk3\/\).*\(\/seq\/\)/\1boss\2/' `
    set output = "cp -pR '$source_dir/$filename' '$target_dir/$filename'"
    
    if ( ! -d $target_dir ) then
        mkdir $target_dir
        chown boss:user $target_dir
    endif
    if ( ! -r "$target_dir/$filename" ) then
        eval $output
        set output = "chown boss:user '$target_dir/$filename'" 
        eval $output
    endif
end 
exit


Last edited by kaklon; 06-18-2008 at 08:51 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying characters on each line in a file

Hello, I would like to copy the first and third char on each line of a file and place them in the 14h and 17th char positions. The file name is listed first and is 6 char's and the dir name is second and also same char size on each line. The file has thousands of lines. Initial... (6 Replies)
Discussion started by: dmm
6 Replies

2. Shell Programming and Scripting

Copying files

I'm trying to do this exact same thing, so far I have created this to move files i've named my script CP.sh #!/bin/bash cd /root/my-documents/NewDir/ for f in *.doc do cp -v $f root/my-documents/NewDir $f{%.doc} done When i go to run this in the console i type, bin/sh/ CP.sh but it... (7 Replies)
Discussion started by: MKTM_93_SIMP
7 Replies

3. Shell Programming and Scripting

Copying files

All, I need to grab and rename common files from several unique directory structures. For example, the directory structures looks like: /unique_dir/common/common/common/person_name_dir/common_file.txt There are over 90,000 of these text files that I'd like to put in a single directory as... (5 Replies)
Discussion started by: hburnswell
5 Replies

4. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

5. Shell Programming and Scripting

Copying Files

Hi All, I'm trying to list some files from my log directory and files are like this log.20110302_20.gz log.20110302_21.gz log.20110302_22.gz log.20110302_23.gz log.20110303_00.gz log.20110303_01.gz log.20110303_02.gz ............ log.20110311_22.gz log.20110311_23.gz... (2 Replies)
Discussion started by: thelakbe
2 Replies

6. UNIX for Advanced & Expert Users

copying of files by userB, dir & files owned by userA

I am userB and have a dir /temp1 This dir is owned by me. How do I recursively copy files from another users's dir userA? I need to preserve the original user who created files, original group information, original create date, mod date etc. I tried cp -pr /home/userA/* . ... (2 Replies)
Discussion started by: Hangman2
2 Replies

7. Solaris

Copying Files

Hi, I understand that to copy files across server, the feasible way will be using scp command. Am I right? What if the two servers are not connected to a network? If by using a cross cable to link up both the server, what will be the best (fastest) way to copy files across? scp as well? ... (3 Replies)
Discussion started by: user50210
3 Replies

8. Shell Programming and Scripting

copying files

hi I want to copy all files from the current directory and move to .archive file. Moreover,I want to add .bak to each file name, that will be copied. How can I do that? (4 Replies)
Discussion started by: tjay83
4 Replies

9. Solaris

Copying Files and

I am new user to solaris and installed solaris operating system on full Harddisk 120Gb. I am unable to copy music files to desktop and /home directory. One thing happened while registering is- i entered login-root and its password. The message prompted your system is crashed. Is it because of... (1 Reply)
Discussion started by: patilmukundraj
1 Replies

10. UNIX for Dummies Questions & Answers

Copying files

I like to know the command structure of copying files/directories from a unix box using telnet session to a windows box. (4 Replies)
Discussion started by: alpheusm
4 Replies
Login or Register to Ask a Question