The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 1 Week Ago 11:44 AM
Find a file in a folder-please help bsandeep_80 UNIX for Dummies Questions & Answers 7 04-17-2008 12:21 AM
Parse the .txt file for folder name and FTP to the corrsponding folder. MeganP Shell Programming and Scripting 3 07-03-2007 10:54 AM
how to differentiate a file from a folder in a FIND? denysQC UNIX for Dummies Questions & Answers 3 06-06-2006 03:02 PM
Find an imported folder? gilr UNIX for Dummies Questions & Answers 2 03-27-2002 02:08 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2006
Registered User
 

Join Date: Jan 2005
Location: Canada
Posts: 9
Take a folder name and find it in another folder (Complicated)

Hi Script Experts,

Here is my scenario:
1. /var/mqm/qmgrs folder will contain 11 folders as follows:
1. /var/mqm/qmgrs/Folder_Name1
....................../Folder_Name2
....................../Folder_Name3
.......
...................../Folder_Name11

2. if Folder_Name1 exists in /export/home/mqm/DR/ini/Folder_Name1
then delete Folder_Name1 from step 1. /var/mqm/qmgrs folder

3. Go back in the loop, take Folder_Name2 and perform step 2. until all 11 Folder_Name11

NOTE:
I did ls -1 /var/mqm/qmgrs/. which is giving me a list of Folder_Name1 thru Folder_Name11

I don't know how to take Folder_Name1 value and see if it exists in step 2 folder.

If somebody can help me here would be highly appreciated!!!

Warm Regards,

Khan
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-05-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,322
Try this:
Code:
cd /var/mqm/qmgrs
for dir in Folder_Name*; do
   if [ -d /export/home/mqm/DR/ini/$dir ]; then
      echo removing $PWD/$dir
      #rm -r $dir
   fi
done
Run the script once with the echo, then if the correct directories are being shown as removing... then you can unhash the rm statement.
Reply With Quote
  #3 (permalink)  
Old 09-05-2006
Registered User
 

Join Date: Jan 2005
Location: Canada
Posts: 9
Hi BlowTorch,

Thank you so much for your quick response. Can I ask you a question,

what is $PWD doing in echo removing $PWD/$dir line

Again, thanx a lot for your help!!!


Warm Regards,

Khan
Reply With Quote
  #4 (permalink)  
Old 09-06-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 363
current dir

You are just giving a message to the screen telling the user which dir you are removing.
'PWD' would contain the value of current directory. Just
Code:
echo $PWD
and see.
Reply With Quote
  #5 (permalink)  
Old 09-06-2006
Registered User
 

Join Date: Jan 2005
Location: Canada
Posts: 9
BlowTorch and Raj,

Thank you so much for all your help. It is working great. I really appreciate it.

I have a similar situation where I like do the following:

Here is my scenario:
1. /var/mqm/qmgrs folder will contain 11 folders as follows:
1. /var/mqm/qmgrs/Folder_Name1
....................../Folder_Name2
....................../Folder_Name3
.......
...................../Folder_Name11

2. if Folder_Name1 exists in /export/home/mqm/DR/ini/Folder_Name1
then update a LogPath line in qm.ini file within /var/mqm/qmgrs/Folder_Name1/qm.ini file

3. Go back in the loop, take Folder_Name2 and perform step 2. until all 11 Folder_Name11

NOTE:
This is what I tried, it is generating a new file under /var/mqm/qmgrs but NOT updating the LogPath line in the qm.ini file.
Code:
cd /var/mqm/qmgrs/
for dir in *; do
    if [ -d /export/home/mqm/DisasterRecovery/ini/$dir ]; then
       echo updating Log Path for $PWD/$dir
       sed -e '/^   LogPath/s/LogPath=\var\/mqm\/log\/$dir\/
             $dir\//LogPath=\/var\/mqm\/log\/$dir\//' /var/mqm/qmgrs/
             $dir/qm.ini >ini.new
    fi
done
Looks like my sed is NOT working properly. If I try the same sed replacing Folder_Name as follows, it is working fine.

sed -e '/^ LogPath/s/LogPath=\/var\/mqm\/log\/CIBOTSP\/CIBOTSP\//
LogPath=\/var\/mqm\/log\/CIBOTSP\//' qm.ini.new > qm.ini

Could you please help me out here.


Warm Regards,

Khan

Last edited by blowtorch; 09-06-2006 at 09:20 AM. Reason: add code tags
Reply With Quote
  #6 (permalink)  
Old 09-06-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,322
Not really able to understand what you are doing in that sed there. Why don't you give an example for one directory name and then someone could help you with what you want.

Here's a tip: when using sed to match/replace for pathnames that contain the "/" character, don't use the "/" as the delimiter/seperator for the sed commands. Use something like "#" instead.
Code:
sed -e 's#LogPath#lOGpATH#g' somefile
works just as well as the more traditional
Code:
sed -e 's/LogPath/lOGpATH/g' somefile
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0