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
shell script to remove old files and write to a log file yabai Shell Programming and Scripting 3 05-21-2008 12:52 AM
Chek if a file exists in Ubuntu and Cent OS using shell script m_kk Shell Programming and Scripting 2 03-26-2008 07:32 AM
Check File Exists and compare to previous day file script rbknisely Shell Programming and Scripting 3 02-07-2008 08:53 AM
unix script to check whether particular file exists and to find its size Balachandar Shell Programming and Scripting 9 02-05-2008 12:56 AM
how to write to file using fprintf in find command... moxxx68 UNIX for Dummies Questions & Answers 2 10-26-2004 04:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-03-2008
Registered User
 

Join Date: May 2008
Posts: 3
Need to write a script in UNIX to find a file if another file exists

So I have a lot of Java applications on my servers all having their own folder from the applications subdirectory. Now, I need to do the following.

Search all the applications subdirectories for message.jar.

If the message.jar file exists, I need to search the application directory for license text.

For example, my application subdirectory consists of the following application folders.

application/messagingApp/
application/databaseApp/
application/toolsApp/

Now when I run the following command from :/application:

:/application % find . message.jar -print

I get the following:
application/messagingApp/common/jars/message.jar
application/toolsApp/jars/message.jar


Now, since I know that the messagingApp and toolsApp contains message.jar, I now need to search all files in the directory (subdirectories don't have to be searched) application/messagingApp and application/toolsApp for the
following text: licenseKey=, and if it doesn't exist, I need to know what the application folder is.

For example, application/messagingApp/licensing.prop contains licenseKey= but there is no file in application/toolsApp that contains licenseKey= and toolsApp should be the output of the program.
Reply With Quote
Forum Sponsor
  #2  
Old 05-04-2008
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 917
Something like this perhaps (untested):

Code:
for dir in $(find . -name message.jar | awk -F/ '{print $2}')
do
    if ! grep -q licenseKey= $dir/*
    then
        echo $dir
    fi
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:02 PM.


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

Content Relevant URLs by vBSEO 3.2.0