The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 08-21-2008 02:44 PM
Find a file in a folder-please help bsandeep_80 UNIX for Dummies Questions & Answers 7 04-17-2008 03:21 AM
Parse the .txt file for folder name and FTP to the corrsponding folder. MeganP Shell Programming and Scripting 3 07-03-2007 01:54 PM
how to differentiate a file from a folder in a FIND? denysQC UNIX for Dummies Questions & Answers 3 06-06-2006 06:02 PM
Find an imported folder? gilr UNIX for Dummies Questions & Answers 2 03-27-2002 06:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-05-2006
hkhan12 hkhan12 is offline
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
  #2 (permalink)  
Old 09-05-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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.
  #3 (permalink)  
Old 09-05-2006
hkhan12 hkhan12 is offline
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
  #4 (permalink)  
Old 09-06-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
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.
  #5 (permalink)  
Old 09-06-2006
hkhan12 hkhan12 is offline
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 12:20 PM.. Reason: add code tags
  #6 (permalink)  
Old 09-06-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0