Sponsored Content
Top Forums Shell Programming and Scripting problem with spaces in filename Post 302527774 by colsinc on Sunday 5th of June 2011 09:46:39 AM
Old 06-05-2011
Fixed :)

Hi Scrutinizer. Thanks for your reply, it really helped! My script is working now. I post the working script here as an example for anyone with a similar problem. I have implemented Scrutinizers suggestions and made some other changes as well.

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` #cut rsync's list to filenames only.

workLength=`wc -l < "$workDir/work"`     #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'`    #extract filename to work on
    FnScurrJob=`cat $workDir/work | sed -n ''$bookmark'p' | sed "s/\//--/g" | sed "s/\ /-/g"`    #creates a version of the file path suitable for use as a file name by replacing / with --
    echo "Start Rescue on " $currJob >> $workDir/runlog    

    from=$srcDir$currJob        
    to=$desDir$currJob
    log=$workDir/ddlog-$bookmark--$FnScurrJob.txt
    
    ddrescue "$from" "$to" "$log" | tee $workDir/ddoutput-$bookmark--$FnScurrJob.txt
    echo `cat $workDir/ddoutput-$bookmark--$FnScurrJob.txt | grep -B 2 Finished | grep errors` >> $workDir/runlog
done
exit

 

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
Glib::BookmarkFile(3pm) 				User Contributed Perl Documentation				   Glib::BookmarkFile(3pm)

NAME
Glib::BookmarkFile - Parser for bookmark files SYNOPSIS
use Glib; $date .= $_ while (<DATA>); $b = Glib::BookmarkFile->new; $b->load_from_data($data); $uri = 'file:///some/path/to/a/file.txt'; if ($b->has_item($uri)) { $title = $b->get_title($uri); $desc = $b->get_description($uri); print "Bookmark for `$uri' ($title): "; print " $desc "; } 0; __DATA__ <?xml version="1.0" encoding="UTF-8"?> <xbel version="1.0" xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks" xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info"> <bookmark href="file:///tmp/test-file.txt" added="2006-03-22T18:54:00Z" modified="2006-03-22T18:54:00Z" visited="2006-03-22T18:54:00Z"> <title>Test File</title> <desc>Some test file</desc> <info> <metadata owner="http://freedesktop.org"> <mime:mime-type type="text/plain"/> <bookmark:applications> <bookmark:application name="Gedit" exec="gedit %u" timestamp="1143053640" count="1"/> </bookmark:applications> </metadata> </info> </bookmark> </xbel> DESCRIPTION
Glib::BookmarkFile lets you parse, edit or create files containing lists of bookmarks to resources pointed to by URIs, with some meta-data bound to them, following the Desktop Bookmark Specification. The recent files support inside GTK+ uses this type of files to store the list of recently used files. The syntax of bookmark files is described in detail in the Desktop Bookmarks Specification, here is a quick summary: bookmark files use a subclass of the XML Bookmark Exchange Language (XBEL) document format, defining meta-data such as the MIME type of the resource pointed by a bookmark, the list of applications that have registered the same URI and the visibility of the bookmark. METHODS
bookmarkfile = Glib::BookmarkFile->new $bookmark_file->add_application ($uri, $name, $exec) o $uri (string) o $name (string or undef) o $exec (string or undef) Adds the application with $name and $exec to the list of applications that have registered a bookmark for $uri into $bookmark_file. Every bookmark inside a "Glib::BookmarkFile" must have at least an application registered. Each application must provide a name, a command line useful for launching the bookmark, the number of times the bookmark has been registered by the application and the last time the application registered this bookmark. If $name is undef, the name of the application will be the same returned by Glib::get_application_name(); if $exec is undef, the command line will be a composition of the program name as returned by Glib::get_prgname() and the "%u" modifier, which will be expanded to the bookmark's URI. This function will automatically take care of updating the registrations count and timestamping in case an application with the same $name had already registered a bookmark for $uri inside the bookmark file. If no bookmark for $uri is found one is created. $bookmark_file->add_group ($uri, $group) o $uri (string) o $group (string) Adds $group to the list of groups to which the bookmark for $uri belongs to. If no bookmark for $uri is found one is created. unix timestamp = $bookmark_file->get_added ($uri) o $uri (string) $bookmark_file->set_added ($uri, $value) o $uri (string) o $value (unix timestamp) Sets the time the bookmark for $uri was added. If no bookmark for $uri is found one is created. ($exec, $count, $stamp) = $bookmark_file->get_app_info ($uri, $name) o $uri (string) o $name (string) Gets the registration information of $name for the bookmark for $uri. See Glib::BookmarkFile::set_app_info() for more information about the returned data. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_app_info ($uri, $name, $exec, $count, $stamp) o $uri (string) o $name (string) o $exec (string) o $count (integer) o $stamp (unix timestamp) Sets the meta-data of application $name inside the list of applications that have registered a bookmark for $uri inside $bookmark_file. You should rarely use this method; use Glib::BookmarkFile::add_application() and Glib::BookmarkFile::remove_application() instead. $name can be any UTF-8 encoded string used to identify an application. $exec can have one of these two modifiers: "%f", which will be expanded as the local file name retrieved from the bookmark's URI; "%u", which will be expanded as the bookmark's URI. The expansion is done automatically when retrieving the stored command line using the Glib::BookmarkFile::get_app_info() method. $count is the number of times the application has registered the bookmark; if it is < 0, the current registration count will be increased by one, if it is 0, the application with $name will be removed from the list of registered applications. $stamp is the Unix time of the last registration, as returned by time(); if it is -1, the current time will be used. If you try to remove an application by setting its registration count to zero, and no bookmark for $uri is found, %FALSE is returned and an exception is fired. May croak with a Glib::Error in $@ on failure. list = $bookmark_file->get_applications ($uri) o $uri (string) Retrieves the names of the applications that have registered the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->get_description ($uri) o $uri (string) Gets the description of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_description ($uri, $description) o $uri (string) o $description (string) Sets the description of the bookmark for $uri. If no bookmark for $uri is found one is created. list = $bookmark_file->get_groups ($uri) o $uri (string) Retrieves the list of group names of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_groups ($uri, ...) o $uri (string) o ... (list) one or more group names Sets a list of group names for the item with URI $uri. Each previously set group name list is removed. If no bookmark for $uri is found one is created. boolean = $bookmark_file->has_application ($uri, $name) o $uri (string) o $name (string) Checks whether the bookmark for $uri inside $bookmark_file has been registered by application $name. May croak with a Glib::Error in $@ on failure. boolean = $bookmark_file->has_group ($uri, $group) o $uri (string) o $group (string) Checks whether $group appears in the list of groups to which the bookmark for $uri belongs to. May croak with a Glib::Error in $@ on failure. boolean = $bookmark_file->has_item ($uri) o $uri (string) Looks whether the bookmark file has a bookmark for $uri. ($href, $mime_type) = $bookmark_file->get_icon ($uri) o $uri (string) Gets the icon of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_icon ($uri, $href, $mime_type) o $uri (string) o $href (string or undef) o $mime_type (string or undef) Sets the icon for the bookmark for $uri. If $href is undef, unsets the currently set icon. boolean = $bookmark_file->get_is_private ($uri) o $uri (string) May croak with a Glib::Error in $@ on failure. $bookmark_file->set_is_private ($uri, $is_private) o $uri (string) o $is_private (boolean) $bookmark_file->load_from_data ($buf) o $buf (scalar) Parses a string containing a bookmark file structure. May croak with a Glib::Error in $@ on failure. ($full_path) = $bookmark_file->load_from_data_dirs ($file) o $file (localized file name) Parses a bookmark file, searching for it inside the data directories. If a file is found, it returns the full path. May croak with a Glib::Error in $@ on failure. $bookmark_file->load_from_file ($file) o $file (localized file name) Parses a bookmark file. May croak with a Glib::Error in $@ on failure. string = $bookmark_file->get_mime_type ($uri) o $uri (string) Gets the MIME type of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_mime_type ($uri, $mime_type) o $uri (string) o $mime_type (string) Sets the MIME type of the bookmark for $uri. If no bookmark for $uri is found one is created. unix timestamp = $bookmark_file->get_modified ($uri) o $uri (string) $bookmark_file->set_modified ($uri, $value) o $uri (string) o $value (unix timestamp) Sets the time the bookmark for $uri was last modified. If no bookmark for $uri is found one is created. $bookmark_file->move_item ($old_uri, $new_uri) o $old_uri (string) o $new_uri (string or undef) Changes the URI of a bookmark item from $old_uri to $new_uri. Any existing bookmark for $new_uri will be overwritten. If $new_uri is undef, then the bookmark is removed. May croak with a Glib::Error in $@ on failure. $bookmark_file->remove_application ($uri, $name) o $uri (string) o $name (string) Removes application registered with $name from the list of applications that have registered a bookmark for $uri inside $bookmark_file. May croak with a Glib::Error in $@ on failure. $bookmark_file->remove_group ($uri, $group) o $uri (string) o $group (string) Removes $group from the list of groups to which the bookmark for $uri belongs to. May croak with a Glib::Error in $@ on failure. $bookmark_file->remove_item ($uri) o $uri (string) Removes the bookmark for $uri from the bookmark file. May croak with a Glib::Error in $@ on failure. integer = $bookmark_file->get_size Gets the number of bookmarks inside the bookmark file. $bookmark_file->get_title ($uri, $title) o $uri (string) Gets the title of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_title ($uri, $title) o $uri (string) o $title (string) Sets the title of the bookmark for $uri. If no bookmark for $uri is found one is created. string = $bookmark_file->to_data Returns the bookmark file as a string. May croak with a Glib::Error in $@ on failure. $bookmark_file->to_file ($file) o $file (localized file name) Saves the contents of a bookmark file into a file. The write operation is guaranteed to be atomical by writing the contents of the bookmark file to a temporary file and then moving the file to the target file. May croak with a Glib::Error in $@ on failure. list = $bookmark_file->get_uris Returns the URI of all the bookmarks in the bookmark file. unix timestamp = $bookmark_file->get_visited ($uri) o $uri (string) $bookmark_file->set_visited ($uri, $value) o $uri (string) o $value (unix timestamp) Sets the time the bookmark for $uri was last visited. If no bookmark for $uri is found one is created. SEE ALSO
Glib COPYRIGHT
Copyright (C) 2003-2011 by the gtk2-perl team. This software is licensed under the LGPL. See Glib for a full notice. perl v5.14.2 2012-05-24 Glib::BookmarkFile(3pm)
All times are GMT -4. The time now is 02:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy