View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

dealing with spaces (“ “) in image names

Andrew Staunton wrote on Jun 15, 2011

I have a set of .fit files with a space (" ") instead of a hyphen ("-") or underscore ("_") separting the components, eg:

first second1.fit
first second2.fit
first second3.fit
etc.

I want to rename them with a connecting character (such as hyphen), eg:

first-second1.fit
first-second2.fit
first-second3.fit
etc.

so step one is list all the files into a text file, say original.txt and then create a second textfile with the spaces replaced by hyphen, call that altered.txt - this much can be done with translit...finally I want to use imcopy to rename them:


imcopy @original.txt @altered.txt 


however, imcopy does not recognise the space and so I get error message:


ERROR: Cannot open image (firstsecond.fit)


ie the space was ignored....

Be grateful for advice on how to deal with this.

Mike Fitzpatrick wrote on Jun 15, 2011

Spaces aren't legal in IRAF filenames, even if you quote or escape them in many cases. Simplest thing is to deal with this outside of IRAF entirely, e.g.

% paste original.txt altered.txt | sed -e "s/^/mv /g" > rename.sh
% sh rename.sh


where I'm assuming the filenames in 'original.txt' have the spaces escaped with a backslash. This will create a 'rename.sh' script using the unix 'mv' command to rename the files.

Note the same issue applies to directory names, e.g. if the path to your data directory is "/home/Andys Computer/data" you may encounter problems.

Last post on Jun 15, 2011