LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2007, 11:51 PM   #1
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Rep: Reputation: 15
read config file parameter values


Hi,

I have a config file as follows
Code:
tpconfig.env

A=value-1
B=value-2
C=value-3
I know I can do this for get each line
Code:
param=`grep -i A filename`
But this only gives me
Code:
A=value-1
How go I check for '=' in the above string(substring)?

How do I get the individual values for A,B,C in ksh?
I don't mind using awk within ksh.

I searched this forum, but found only solutions for C or Java.

Thanks
 
Old 02-15-2007, 12:45 AM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Just source the file:

Code:
. /somedir/tpconfig.env
(that's a period-space at the begining of the line)

This will make the variables assigned part of the environment of the current script.
 
Old 02-15-2007, 01:55 AM   #3
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by macemoneta
Just source the file:

Code:
. /somedir/tpconfig.env
(that's a period-space at the begining of the line)

This will make the variables assigned part of the environment of the current script.
Thanks for the reply. However I am not looking to source this file.

So far I have this
Code:
awk -F "=" '            \
$1=="A"                 \
{                       \
  if ($2 == "value-1")  \
      print "yipee";    \
  else                  \
      print "oops";     \
                        \
 }                      \
' /etc/tpconfig.env
Where do I put the else if?

I want something like this
Code:
if $1="A"
{
    if ($2="value-1")
        action-1
    else
        action-2
    end if
}
elsif $1="B"
{
     if ($2="value-2")
        action-1
    else
        action-2
    end if
}
.
.
.

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read parameters from config file (file parser?) alaios Programming 8 07-09-2012 11:29 AM
checking for null values from config file? zerointeger Programming 1 10-12-2005 11:29 AM
read options from config file biiiep Programming 4 05-05-2005 03:30 AM
How to change parameter values of a function in shell script? Bassam Programming 0 01-25-2004 09:52 AM
Unable to read config file............ FXRS Linux - Software 7 07-03-2003 08:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration