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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Back up files to different directory 1

Status
Not open for further replies.

LGJ

Programmer
Mar 7, 2003
50
0
0
GB
Hi all,

Please can I get some help. I need to copy some files for back up purposes into another directory.

All the files are called "pin.conf".

I can do:
================
#!/usr/bin/ksh

cd /opt/6.5/

for filen in `find . -name pin.conf`
do
echo ${filen}
done

==================
OUTPUT:

./source/apps/ouk_credit_reset/pin.conf
./source/apps/ouk_inact_acc_deletion/pin.conf
./sys/test/pin.conf
./sys/test/user_account/pin.conf

===================

Instead of the echo I wish to copy the file to say ~/tempdir/ with a name like source.apps.ouk_credit_reset.pin.conf (the file name now shows what directory it is originally from and is unique for each pin.conf file).

I can't work out how to change the / to . in the filename??

Does this make sense?

Thanks
LGJ
 
Hi there,

Use the translate command tr (see man pages)

eg:
echo ${filen} | tr '/' '.'

(you'll need to get round the initial ./ of the output first or remove the .. afterwards)

I hope that help.

Mike
 
Hi there,

In the time it takes to start typing, get interrupted and then finish typing, someone has posted a similar reply. At least you know your on the right track.

Best wishes,

Mike
 
thanks guys, great help.

Learning something every day.

Cheers
LGJ
 
You may also try something like this:
cp $filen $HOME/tempdir/`echo $filen | sed 's!^./!!;s!/!.!g'`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top