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
reading from a file and pass as variables and ignore # in the file konark Shell Programming and Scripting 4 11-08-2007 12:55 AM
Reading Multiple Variables From a Single Line in Shell Drek Shell Programming and Scripting 14 12-21-2006 08:20 AM
Reading file names from a file and executing the relative file from shell script anushilrai Shell Programming and Scripting 4 03-10-2006 02:25 AM
Reading a CSV file into shell variables problem multidogzoomom Shell Programming and Scripting 6 10-11-2005 01:43 PM
shell script, reading and resetting local variables b888c UNIX for Dummies Questions & Answers 1 08-20-2001 01:52 PM

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

Join Date: Jan 2006
Posts: 8
reading variables from a file

Hi,

Could anyone help me in understanding what I am missing..
I have a text file with the following info.

INFILE=>

#Name Variable=<value>
#---------------------------------
name1 inargs="-a Filename1.$VAR.csv -f Filename2.$VAR.csv -c File.c"
name1 incond="Filename1.$VAR.csv Filename2.$VAR.csv"

I want to get the inargs and incond when the name1 is given. I am doing the following -
NAME="$1" (and I pass name1 for NAME)
eval `grep -v \# $INFILE | awk "\\$1 == \"$NAME\" {print \\$2}", but I am getting nothing.

anyhelp is appreciated.

thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 03-12-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
Code:
#!/bin/ksh

NAME='name1'
file='tt.txt'

eval $(nawk -v q='"' -v name="${NAME}" '
  BEGIN {
   PATinags="inargs"
   PATincond="incond"
  }
  $1 == name {
      v="_unknown_"
      if ( $2 ~ ("^" PATinags) )
         v= PATinags
      if ( $2 ~ ("^" PATincond) )
         v= PATincond
      if (split($0, tmpA, q) >= 3 )
         printf("%s=\"%s\"\n", v, tmpA[2])
  }' "${file}" )

echo "inargs->[${inargs}] incond->[${incond}]"
Reply With Quote
  #3  
Old 03-12-2006
Registered User
 

Join Date: Jan 2006
Posts: 8
Thanks a lot. that works..., I will try to understand how you have done it. I thought we might get it with the one line/two lines using awk.
Reply With Quote
  #4  
Old 03-12-2006
Registered User
 

Join Date: Jan 2006
Posts: 8
Hi vgersh99,

could you explain what the split is doing in your solution..., thanks.
Reply With Quote
  #5  
Old 03-13-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
Quote:
Originally Posted by ttshell
Hi vgersh99,

could you explain what the split is doing in your solution..., thanks.
it splits a record/line with double-quote as a separtor splacing the results into an array tmpA.
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 09:54 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