reading variables from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading variables from a file
# 1  
Old 03-12-2006
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.
# 2  
Old 03-12-2006
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}]"

# 3  
Old 03-12-2006
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.
# 4  
Old 03-12-2006
Hi vgersh99,

could you explain what the split is doing in your solution..., thanks.
# 5  
Old 03-13-2006
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading multiple variables in a loop

Hi, I managed to read and print variable as shown in the below code. table_name=table1,table2,table3 i=0 IFS="," for i in $table_name do echo $i done Is there a way how I can read more than one variable. For example I need to read 2 variables and populate the output... (6 Replies)
Discussion started by: shash
6 Replies

2. Shell Programming and Scripting

Reading control characters into variables

Hi, I am trying to write a shell script to help with some digital signature work currently being undertaken where we have a file that contains a number of rows ending with ^M. What I need to do is concatenate this using shell scripting and retain the control character. E.G. abc^M... (5 Replies)
Discussion started by: chris01010
5 Replies

3. Shell Programming and Scripting

Error reading two input variables

Hello all, I've been out of programming for awhile so sorry about the stupid, elementary question. I'm trying to read two inputs and compare them to a list entered as a parameter via the terminal. The script is #!/bin/bash read -p "Enter the numbers" NUM1 NUM2 for VALUE in $@; do ... (6 Replies)
Discussion started by: EnduranceMan
6 Replies

4. Shell Programming and Scripting

Bash: Reading a file and assigning variables from file

I have a file that has four values on each line and I'd like to give each column a variable name and then use those values in each step of a loop. In bash, I believe you could use a while loop to do this or possibly a cat command, but I am super new to programming and I'm having trouble decoding... (2 Replies)
Discussion started by: ccorder22
2 Replies

5. Shell Programming and Scripting

Reading variables from a file

Hi, I have an issue that hope someone will be able to help me with.... I'm using a while-read loop to read lines from a file that contain variables, and I want the variables substituted, but I can't get it to work - the below example with explain: while read line do echo $line ... (5 Replies)
Discussion started by: AndyG
5 Replies

6. Shell Programming and Scripting

Help with reading and assigning variables

Hi Gurus, I have a file named log with 2 lines Each line is a file name. eg $ cat log monday tuesday I need to read log and assign each output(filename) to a different variable. The following doesn't work:- while read A B do echo " a is ${A} " echo " b is ${B} " done <... (6 Replies)
Discussion started by: wisdom
6 Replies

7. Shell Programming and Scripting

Reading Awk lines into variables help plz

I have output from luxadm display commands as below :- DEVICE PROPERTIES for disk: /dev/rdsk/c10t60020F200000C8083F951F4C00012863d0s2 Vendor: SUN Product ID: T300 Revision: 0201 Serial Num: Unsupported Unformatted capacity:... (0 Replies)
Discussion started by: lavascript
0 Replies

8. Shell Programming and Scripting

Reading variables from CSV file

Hi I am using KSH and trying to read variables from a csv file. I've set the IFS=, and it workds. Problem is where one of the values is text containing a comma. For example the following lines exist in my file. How can I read everything between the quotes into a single variable? APW13812,,1... (2 Replies)
Discussion started by: ventris
2 Replies

9. Shell Programming and Scripting

reading external variables does not work

... declare vINIFILE vINIFILE=$1 ... echo "The name of the File is $vINIFILE" >>mail_tmp echo "" >> mail_tmp.$$ ... grep RUNJOB=0 $vINIFILE >>tmp_filter ... So the strange is in echo-statement I get the correct output for $vINIFILE wrtitten into the file mail_tmp. But the... (2 Replies)
Discussion started by: ABE2202
2 Replies

10. Shell Programming and Scripting

reading from a file and pass as variables and ignore # in the file

file.txt contains ------------------ sat1 1300 #sat2 2400 sat3 sat4 500 sat5 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat3.ksh sat4.ksh 500 sat5.ksh my try ------- (4 Replies)
Discussion started by: konark
4 Replies
Login or Register to Ask a Question

Featured Tech Videos