Sponsored Content
Top Forums Shell Programming and Scripting problem with spaces in filename Post 302527742 by colsinc on Sunday 5th of June 2011 03:40:38 AM
Old 06-05-2011
problem with spaces in filename

I have written a script to run ddrescue on a list of files.

Code:
#!/bin/bash
#
# A script to rescue data recursively using ddrescue.

srcDir=/damaged/hdd/movies/              #the source directory
desDir=/new/hdd/movies/                 #the destination directory
workDir=/new/hdd/movies/ddrescue        #location to store logs and working files

#preamble: I have already run rsync to copy files, but some failed part way through.

`rsync -rvn --size-only $srcDir* $desDir | sed "/speedup/d" | sed "/bytes\/sec/d" | sed "/sending\ incremental/d" | sed "/^$/d" > $workDir/work` #use rsync to generate list of partially transferred files.

workLength=`cat $workDir/work | wc -l`        #Find number of files in list.  For use with incrementing.
bookmark=0                    #Begin at first entry in list.

while [ $bookmark -lt $workLength ]
do
    bookmark=`expr $bookmark + 1`        #increment through the list
    currJob=`cat $workDir/work | sed -n ''$bookmark'p' | sed 's/\ /\\\ /g'`    #extract nth filename from list, replace spaces with "\ "
    echo "Start Rescue on " $currJob >> $workDir/runlog    #

    from=`echo $srcDir$currJob`        #creates full filename for source file,
    to=`echo $desDir$currJob`        #destination file,
    log=`echo $workDir/ddlog-$bookmark`    #and ddrescue log file.
    
    `ddrescue $from $to $log > $workDir/ddoutput-$bookmark` #run ddrescue, dumping output to file.
    cat $workDir/ddoutput-$bookmark | grep -B 2 Finished | grep errors >> $workDir/runlog    #read last 3 lines from ddrescue output and record it in runlog, so user can check which files are missing bits.
    echo -e "\n"
done
exit

My problem is that ddrescue does not like the filenames I am giving it. If the filename has spaces in it it says
Code:
ddrescue: too many files

but if it has no spaces I get
Code:
ddrescue: cannot open input file: No such file or directory

I have tried using "quotes" instead of \'ing every space, but no luck. If I replace the command 'ddrescue' with 'echo', run the script, and then manually copy the given filenames into ddrescue in another terminal it works fine. But this rather defeats the purpose..

I have only been learning scripting for a little while, so I feel like I must be missing something obvious, I just can't figure out what!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading a file using sh with spaces in filename

Hi I am trouble parsing through a file with spaces in the filename. I need to grab "supportIDPS/SCM/windows_install/file groups/dds.fgl" and then do a md5sum on it. I am using sh. Any help is appreciated. Here is an example of the input file: 7eedbc9f7902bf4c1878d9e571addf9a ... (4 Replies)
Discussion started by: jekl5
4 Replies

2. Shell Programming and Scripting

copying files with spaces in the filename

Hi I am having difficulty copying files from one dir to another due to a space in the names of the file with an extension .rtf There are a group of files and the command am using is cp `ls -rt /wlblive/home/whiops/ops/RTFs/*.rtf|head -20` /wlblive/home/jamshed Since the files are... (3 Replies)
Discussion started by: jamshedj
3 Replies

3. Shell Programming and Scripting

List files with spaces in filename

I have a text file containing files in a directory structure i.e. /project/hr/raw/jcpdatav/datav_aug03 /project/hr/raw/jcpdatav/comb8121sep02n /project/hr/raw/jcpdatav/datav_feb04_ons /project/hr/raw/jcpdatav/corpsick_jun06 /project/hr/raw/jcpdatav/jcpjoiners200507... (3 Replies)
Discussion started by: mr_crosby
3 Replies

4. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

5. Shell Programming and Scripting

ftp var for filename with spaces

Hello all, I am having difficulties writing an ftp script to retrieve a file via get using a variable name to pass the file name. I know the name of the file I am going to retrieve, this file name has embedded spaces and punctuation in the name itself. If I interactively use the get and I... (10 Replies)
Discussion started by: gio001
10 Replies

6. Shell Programming and Scripting

spaces in filename

Hello I canīt find an answer to my problem. I am trying to tar some files with spaces #!/bin/sh files="/var/installer/server Config /var/installer/client user /var/installer/Svenskt Language /var/installer/GUI user Plugin /var/installer/Firefox Plugin" tar -czvf /tmp/files.tar.gz... (14 Replies)
Discussion started by: Lusen
14 Replies

7. Shell Programming and Scripting

Replacing white spaces in filename

Hi; In following code find LOG_DIR -type f | while read filename; do echo $filename; done I want to precede each white space encountered in filename with \ so that when i use $filename for running some commands in do...done,it wont give me an error. will appreciate ur help in this.... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

8. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

9. Shell Programming and Scripting

Remove spaces in filename

Hi team, Here's a requirement for me. Here are the list of files i have in a unix directory. W 2 A D_2014.csv W 3 A D_2014.csv W 4 A D_2014.csv /home/kmani00-> uname -a AIX sliyyvxx 1 6 00F613E54C00 /home/kmani00-> The file names has to be without spaces as follows. W2AD_2014.csv... (1 Reply)
Discussion started by: kmanivan82
1 Replies

10. Shell Programming and Scripting

Dealing with filename spaces in Perl

The following command to replace text in place in multiple files in a directory is tripping up on filename spaces (Windows environment). I really don't know Perl. find '\\server\directory' | xargs perl -pi -e 's/textA/textB/g'Mike (2 Replies)
Discussion started by: Michael Stora
2 Replies
KBOOKMARKMERGER 
KDE User's Manual KBOOKMARKMERGER NAME
kbookmarkmerger - A program for merging a given set of bookmarks into the user's list of bookmarks. SYNOPSIS
kbookmarkmerger [Qt Options...] [KDE Options...] {directory} DESCRIPTION
kbookmarkmerger is a program for merging a given set of bookmarks into the user's set of bookmarks; if the user doesn't have any bookmarks created yet, a new bookmark list is created and the given bookmarks are inserted into it. While doing this, kbookmarkmerger keeps track of which files were merged in a previous run already, so no bookmark will get installed to the user's bookmarks more than once. In case KDE is running while kbookmarkmerger is executed, the KDE bookmark subsystem will be informed of any changes to the user's bookmarks, so that all applications accessing that information (i.e.Konqueror) will pick the changes up instantly. The traditionally used approach to achieve something like this was to use carefully crafted skeleton home directories when creating a new user account, to provide the user with a standard set of bookmarks. The problem with this approach is that after the user account has been created, no new bookmarks can be propagated. This mechanism is useful for system administrators who want to propagate a bookmark pointing to a certain document (for instance, important notes about the system) to all users. Distributors might find it useful as well, for instance by augmenting the software packages they supply with bookmark files which kbookmarkmerger merges into the user's bookmark list when the package is installed. That way, documentation shipped with a software package is easily and visibly accessible right after the package has been installed. The only parameter required by kbookmarkmerger is the name of a directory which shall be scanned for bookmark files. All files in the given directory will be considered for being merged into the user's setup. The files in the given directory should be valid XBEL files. SEE ALSO
Konqueror manual[1] EXAMPLES
joe@hal9000:~> kbookmarkmerger /usr/local/extra-bookmarks Merges all bookmark files stored in /usr/local/extra-bookmarks into joe's list of bookmarks. STANDARDS
XBEL specification[2] RESTRICTIONS
When determining whether a given bookmark file has been merged into the user's bookmarks already or not, kbookmarkmerger merely looks at the filename of the bookmark file - the contents are not checked at all. This means that changing a bookmark file which was already merged into a user's bookmarks will not trigger merging it once again. Also note that in case a user modifies a bookmark which was merged into his setup, the original bookmark file will be left unmodified. AUTHOR
Frerich Raabe<raabe@kde.org> AUTHOR
Frerich Raabe <raabe@kde.org> Author. NOTES
1. Konqueror manual help:/konqueror/index.html 2. XBEL specification http://pyxml.sourceforge.net/topics/xbel/ K Desktop Environment February 1st, 2005 KBOOKMARKMERGER
All times are GMT -4. The time now is 01:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy