Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find and Rename Filename

Status
Not open for further replies.

simonial

MIS
Sep 13, 2002
1
US
Hi,
The below script does not cp the file which has special charactor such as ~!@#$%^&*()_+ and stop process on the remaining files. I would like to change the script which able to skip the file or rename it to make it able to copy. Anyone here can help me or give me some advise.

Thank you


#!/bin/csh

set SERVER="emsun8"
set DB_INSERT="/home/production/data/db_insert"
set STDF_OEE="/export/home/db_inputs/a53x_ws"

cd $DB_INSERT
set XFR_LIST = ( `ls *stdf` )

foreach STDF ($XFR_LIST)
if ( -e ${STDF:t} ) then
rcp -p ${STDF:t} ${SERVER}:${STDF_OEE}/wait_${STDF:t}
else
echo " "
echo "$STDF not found."
echo " "
endif
end

exit 0



 
its bad practice to write csh-scripts, use sh or ksh. ------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
Not sure I'd agree that it's always bad practice to use csh - but I never do. I've come up with this (in ksh) which (for some reason I can't figure) has to be run twice. The first time it seems to ignore files with one * in the name ... but next time it picks up this file. Help anyone?

Anyway - it's a start:

find . -name "*[*~@!#$%^&()_+]*" -print > filelist
count=1
for file in `cat filelist`
do
mv $file filename.$count.$$
count=`expr $count + 1`
done

I have no doubt that someone can do something which works better and is more concise/elegant.
 
you have problems with metachars
i am working on a russian kb, sorry for typos change ' with appropriate backquote the first and last in find cmd.

mask all special chars
NOTA modern 'find' do not need '-print'
's/\*/\\\&/p' == mask special char *
*~$%^& are sure special chars
() my be too, i don't remember in this context


xx=0
for file in 'find .|sed -ne 's/\*/\\\&/p;/@/p;s/\%/\\\&/p; and so on'
do
mv $file newfile$xx
xx='expr $xx + 1'
done ------------ jamisar
Einfachheit ist das Resultat der Reife. (Friedrich Schiller)
Simplicity is the fruit of maturity.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top