![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Hi vgersh99,
could you explain what the split is doing in your solution..., thanks. |
|
#5
|
||||
|
||||
|
Quote:
|
||||
| Google The UNIX and Linux Forums |