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.
C-shell Cookbook