next up previous 405
Next: File operators
Up: Filename modification
Previous: Appending a counter to the input filename


Appending to the input filename

Whilst appending a suffix after each data-processing stage is feasible, it can generate some long names, which are tedious to handle. Instead you might want to replace part of the input name with a new string. The following creates another shell variable, ndfout by replacing the string _flat from the input NDF name with _sm. The script pipes the input name into the sed editor which performs the substitution.

     foreach file (*_flat.sdf)
        set ndf = $file:r
        set ndfout = `echo $ndf | sed 's#_flat#_sm#'`
        block in=$ndf out=$ndfout accept
     end
The # is a delimiter for the strings being substituted; it should be a character that is not present in the strings being altered. Notice the ` ` quotes in the assignment of ndfout. These instruct the shell to process the expression immediately, rather than treating it as a literal string. This is how you can put values output from UNIX commands and other applications into shell variables.

next up previous 405
Next: File operators
Up: Filename modification
Previous: Appending a counter to the input filename

C-shell Cookbook
Starlink Cookbook 4
Malcolm J. Currie
2006 November 26
E-mail:ussc@star.rl.ac.uk

Copyright © 2009 Science and Technology Facilities Council