![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| shell script to find and replace string in multiple files | pharos467 | Shell Programming and Scripting | 11 | 01-15-2009 11:40 AM |
| Replace text in multiple files | on9west | Shell Programming and Scripting | 1 | 05-20-2008 01:35 AM |
| Find and replace a string in multiple files | pharos467 | UNIX for Dummies Questions & Answers | 2 | 11-05-2007 11:47 PM |
| Find and Replace in multiple files (Shell script) | jatins_s | Shell Programming and Scripting | 13 | 11-05-2007 02:11 PM |
| How can I replace multiple lines from different files | ranga27 | Shell Programming and Scripting | 2 | 02-07-2007 08:57 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Find and replace files in multiple folders
Hi there,
I would like to write a script to automate the copy and renaming of files in multiple dir. I have a generic file named s253e.prb and would like to copy this to multiple dir and rename it. Example: Dir is AL-M1 and the prb file name is AL-M1.prb. I would like to be able to copy the generic prb file to this dir and rename it AL-M1.prb while backing up the original. I know that I can use the find command to complete this but I dont know where to start.. The Generic file is kept in the dir S25E3 dir and again we have multiple dirs: AL-M1 AL-M2 CD-M1 etc Any starters and help would be grateful to point me in the right dir... I am using the ksh shell for this |
|
||||
|
All the directories are in the smae path ie:
/users/clyons/probes/ One other question (the script above works and thanks for it )The s25e3.prb file is also contaained within this dir structure. How would I get the scrit to ignore this dir so that an error message is not created (see attached screen capture) Again thanks for all your help on this |
|
|||||
|
It isn't an error, just a warning, but you can ignore this directory. Just shove an if in there.
Code:
cd /parent/dir/to/all/work/dirs
for dir in *; do
if [ "$dir" = "s25e3" ]; then #you can replace this with whatever dir you want to ignore
continue
fi
cp -p $dir/${dir}.prb $dir/${dir}.prb.backup
cp /path/to/s253e.prb $dir/${dir}.prb
done
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|