Sponsored Content
Top Forums Shell Programming and Scripting reading variables from a file Post 101731 by vgersh99 on Sunday 12th of March 2006 01:15:06 PM
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}]"

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
variable(n)						       Tcl Built-In Commands						       variable(n)

__________________________________________________________________________________________________________________________________________________

NAME
variable - create and initialize a namespace variable SYNOPSIS
variable ?name value...? name ?value? _________________________________________________________________ DESCRIPTION
This command is normally used within a namespace eval command to create one or more variables within a namespace. Each variable name is initialized with value. The value for the last variable is optional. If a variable name does not exist, it is created. In this case, if value is specified, it is assigned to the newly created variable. If no value is specified, the new variable is left undefined. If the variable already exists, it is set to value if value is specified or left unchanged if no value is given. Normally, name is unqualified (does not include the names of any containing namespaces), and the variable is created in the current namespace. If name includes any namespace qualifiers, the variable is created in the specified names- pace. If the variable is not defined, it will be visible to the namespace which command, but not to the info exists command. If the variable command is executed inside a Tcl procedure, it creates local variables linked to the corresponding namespace variables (and therefore these variables are listed by info vars.) In this way the variable command resembles the global command, although the global command only links to variables in the global namespace. If any values are given, they are used to modify the values of the associated namespace variables. If a namespace variable does not exist, it is created and optionally initialized. A name argument cannot reference an element within an array. Instead, name should reference the entire array, and the initialization value should be left off. After the variable has been declared, elements within the array can be set using ordinary set or array commands. EXAMPLES
Create a variable in a namespace: namespace eval foo { variable bar 12345 } Create an array in a namespace: namespace eval someNS { variable someAry array set someAry { someName someValue otherName otherValue } } Access variables in namespaces from a procedure: namespace eval foo { proc spong {} { # Variable in this namespace variable bar puts "bar is $bar" # Variable in another namespace variable ::someNS::someAry parray someAry } } SEE ALSO
global(n), namespace(n), upvar(n) KEYWORDS
global, namespace, procedure, variable Tcl 8.0 variable(n)
All times are GMT -4. The time now is 06:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy