How to Read different values from external file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Read different values from external file?
# 1  
Old 07-10-2011
How to Read different values from external file?

Hi ,
I am new to this scripting , I am facing an issue like how to read different values from external file by using different variables,
In script I supposed to declare
var 1
var 2
var 3
I know how to call this variables from external file (I am using awk command by giving same name in script and extrnal file Smilie), but the problem is here,
suppose I gave in awk command var1 is string1, var2 is string2 and var3 is string3

in external file i am having these values
string1 value1,value2,value3
string2 value4,value5,value6
string3 value7,value8,value9
now my update query has run only at a time
value 1, value 4 and value 7 , next run value 2,5,8 and value3,value6 and value9

I hope i gave you proper explanation Smilie about my problem,
Can some one give idea how to read these different variables in to script recursively..

Thanks in advance
# 2  
Old 07-10-2011
You want to read in values using awk, and then use them in shell script?

It may be easier to use only shell, or only awk, to do all processing.

It would help a lot to see what you have now, and/or sample of desired input and output.
# 3  
Old 07-10-2011
If I understand what you want, you can read into variables inside shell like this:

Code:
while IFS="," read A B C D
do
        echo "A=$A B=$B C=$C D=$D"
done < datafile

The IFS controls what it splits on. By default it's whitespace.
# 4  
Old 07-11-2011
Hi Corona,
Thank you very much, I implemented with your logic, it works fine,
this is the logic I wrote in scrpt
Code:
infile=`more ${mydir} | grep 'TEXTINFO' | awk '{print $2}`
while IFS="," read var1 var2 var3
do
  update query 
done < $infile


Last edited by Franklin52; 07-11-2011 at 02:19 PM.. Reason: Please indent your code and use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH script to read external file to perform text replacements?

Hi all, I have a moderate size (300 lines) BASH Shell script that performs various tasks on different source reports (CSV files). One of the tasks that it performs, is to use SED to replace 'non-conforming' titles with conformant ones. For example "How to format a RAW Report" needs to become... (3 Replies)
Discussion started by: richardsantink
3 Replies

2. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

3. Shell Programming and Scripting

Read values from second file in awk

Hello Friends, I have written a script like the following, which finds some logs and fetchs some desired rows and then calculate average processing time of a spesific application. if then echo echo "----- There are three arguments which is expected to run this script! ... (5 Replies)
Discussion started by: EAGL€
5 Replies

4. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

5. Shell Programming and Scripting

Read values from file.

I have a config file of this format: Company= Alpha Tech From Email = AlphaTech@Alphatech.com Pass = Passowrd To Email = abc@hotmail.com Smtp=smtp.live.com:587 I want to read these values from this file and use in a command to send email. I am trying grep but it gives full line. I just... (8 Replies)
Discussion started by: kashif.live
8 Replies

6. Shell Programming and Scripting

Read variables and their values from file

Hi, I want to read the variables and the values from the txt file and compare these values with the ones computed by script. for ex: say var.txt contains the variable names and their values: one 1 two 2 three 3 The value of variables "one" "two" and "three" will be computed in the script... (3 Replies)
Discussion started by: bhushana
3 Replies

7. Shell Programming and Scripting

Read values from a file

Hi , I have a file with the following content I need the read the year and reporting from this file and store them in variables. I understand that we can read the file delimited by'=' but not sure how to extract the values correctly. Thanks in advance Regards (3 Replies)
Discussion started by: w020637
3 Replies

8. Shell Programming and Scripting

how to read only the first two values from a file in unix

Hi, I'm new to unix.. I need to read only the first two values from a file that contains many data....My record is like this FTG_ver_num=7.0 RUN_ID=2 $$tgt_envrnmt_cd=FTG $$WRK_FLW_CD=NPL I need oly the values of ETG_ver_num and RUN_ID. i.e) output to be 7.0 and 2 The code i used... (2 Replies)
Discussion started by: raghulshekar
2 Replies

9. Shell Programming and Scripting

how do I pass or read values from file ?

Hi one & All , My Need is to Create 64 Partition and create File System in Linux. I have the Script ... for((a=0;a<=63;a++)) do fdisk /dev/cciss/c0d$a done for((a=0;a<=63;a++)) do mkfs.ext2 /dec/cciss/'c0d'$a'p1' done the moment I run the Script I get the Prompt ... Command... (1 Reply)
Discussion started by: nix-kid
1 Replies

10. UNIX for Dummies Questions & Answers

How can I read variable values from file?

Hi, I want to pratmeterze my scripts like, my confRsync file contains varibale values for 1. host 2. Destination and 3. source like this, I want to read this values from this and assing to my makeRsyn.sh file's varibales. how to do this? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question