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
Regarding Shell Scripting anilkarikkandar UNIX for Dummies Questions & Answers 3 11-19-2006 09:26 PM
HELP PLS!! Shell Scripting!! Mary_xxx Shell Programming and Scripting 9 09-16-2006 03:52 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
something else on shell scripting master_6ez Shell Programming and Scripting 1 11-21-2004 08:42 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-21-2002
Registered User
 

Join Date: Feb 2002
Location: Chicago IL
Posts: 41
Question Shell scripting ??

I have a file in /etc/ called oratab

how do i read the file
# *:/apps/oracle/product/8.1.6ctmdev01:N
# *:/apps/oracle/product/8.1.6ctmdev01:N
QBIP:/apps/oracle/product/8.1.6qbip01:Y
QBID:/apps/oracle/product/8.1.6qbid01:Y
QBIT:/apps/oracle/product/8.1.6qbit01:Y

and read
QBIP
QBID
QBIT
into Oracle_value variable and pass that variable into my shell script?? the purpose is to run that 1 script on 3 instances??
Reply With Quote
Forum Sponsor
  #2  
Old 10-21-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
try this...

Oracle_value=`cut -d : -f 1 /etc/oratab | grep '[A-Z]+' | sed 's/\n/ /'`

this will put "QBIP QBID QBIT " in Oracle_value


Vishnu.
Reply With Quote
  #3  
Old 10-21-2002
Registered User
 

Join Date: Feb 2002
Location: Chicago IL
Posts: 41
Question

Vishnu
thanks for the info

the problem is to avoid # or * and how do i read thru the file??

# *:/apps/oracle/product/8.1.6ctmdev01:N
# *:/apps/oracle/product/8.1.6ctmdev01:N
QBIP:/apps/oracle/product/8.1.6qbip01:Y
QBID:/apps/oracle/product/8.1.6qbid01:Y
QBIT:/apps/oracle/product/8.1.6qbit01:Y


Jigar
Reply With Quote
  #4  
Old 10-21-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,653
How about something like this:
Code:
#! /usr/bin/ksh

IFS=:
exec < /etc/oratab
while read Oracle_value junk ; do
        firstchar=${Oracle_value%${Oracle_value#?}}
        [ $firstchar = '#' ] && continue
        echo  Oracle_value =  $Oracle_value
done
exit 0
Reply With Quote
  #5  
Old 10-21-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
Oracle_value=`cut -d : -f 1 /etc/oratab | grep '[A-Z]+' | sed 's/\n/ /'`

in this cut will isolate the first column in all lines using : as separator and [A-Z]+ in grep ensures that you dont read the columns having # etc and sed replace newlines with spaces.

If you want a loop in which you can pass the content of whole lines having QBIP etc. You may try this..

while i in `grep '^[A-Z]+:.*$' /etc/oratab`
do
echo $i
done

this will echo only those lines beginning with all caps and ending with a : . So effectively isolating those lines containing QBIP etc.
Reply With Quote
  #6  
Old 10-21-2002
Registered User
 

Join Date: Aug 2002
Location: Marlboro, MA
Posts: 114
sorry..

replace "while i in" in my above reply with "for i in"...

thank you!
Vishnu.
Reply With Quote
  #7  
Old 10-25-2002
Registered User
 

Join Date: Oct 2002
Location: United Kingdom
Posts: 9
How about this


awk -F":" '/^[A-Z]/ { print $1}'

/<reg exp>/ will remove unwanted lines.
__________________
Thanks
Vikas Srivastava
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 03:21 AM.


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