Error in fetching multiple row values into variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in fetching multiple row values into variables
# 1  
Old 02-02-2011
Error in fetching multiple row values into variables

Hello Team,

In the below code....The variabe values are not fetch from input table into SELECT statements.

Code:
===========================
#!/usr/bash
DATABASE=XXXXX
inputFILE=$1

db2 connect to $DATABASE

TABLENAME=`echo $inputFILE|awk '{print $1}'`
COLUMNNAME=`echo $inputFILE|awk '{print $2}'`

db2 "select substr(tabname,1,20) AS TABLENAME ,substr(COLNAME,1,20) AS COLUMNSNAME ,COLNO as COLUMNPOS 
from syscat.columns where TABNAME='$TABLENAME' and COLNAME='$COLUMNNAME'";

db2 connect reset;
=============================================

Out put coming is :

TABLENAME COLUMNSNAME COLUMNPOS
-------------------- -------------------- ---------
0 record(s) selected.

i.e is there any syntax error in the above code? why the TABLENAME and COLUMNAME are not fetching into SELECT statements?

any suggessions please?
# 2  
Old 02-02-2011
You're doing an echo filename here Smilie you need to do a cat filename.
Code:
TABLENAME=`cat $inputFILE | awk '{print $1}'`

Say if the file is something like this:
Code:
Table1 Column1
Table2 Column2
Table3 Column3

Then the command I've mentioned would give you output like this:
Code:
TABLENAME=`cat $inputFILE | awk '{print $1}'`
COLUMNAME=`cat $inputFILE | awk '{print $2}'`

echo $TABLENAME
echo $COLUMNAME

Output:
Table1 Table2 Table3
Column1 Column2 Column3

Are you sure that this is what you want it to do?
# 3  
Old 02-02-2011
Or use:
Code:
read TABLENAME COLUMNAME x < "$inputFILE"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract multiple values into corresponding variables

Here is my input # MANIFEST.MF Manifest-Version: 1.0 Build-Jdk: 1.6.0 Built-By: CM_TEAM Build_SvnRev: 662789 Build_Number: 13.0.0.0-JDK8 Build_Date: Wed 04/05/2017-20:48:19.17 Archiver-Version: Plexus Archiver Created-By: Apache Maven 3.1.0 Here is the expected output:... (4 Replies)
Discussion started by: kchinnam
4 Replies

2. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies

3. Shell Programming and Scripting

Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello, I would like to ask for help with csh script. An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that... (7 Replies)
Discussion started by: FMMOLA
7 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

[Solved] Counting The Number of Lines Between Values with Multiple Variables

Hey everyone, I have a bunch of lines with values in field 4 that I am interested in. If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out LOW and the number of lines with those values in between 1 and 3,... (2 Replies)
Discussion started by: VagabondGold
2 Replies

6. Shell Programming and Scripting

Help with multiple variables into one row in CSV!

I'm new to shell scripting so I'm guessing I'm just not looking at this from the correct angle as this has to be a common task. What I'm trying to do is take data I've compiled for servers (Name, IPs, HBA WWN's, Storage, etc) and trying to turn that into one row in a CSV file. So File1:... (3 Replies)
Discussion started by: The_Grim_Coder
3 Replies

7. Shell Programming and Scripting

Extracting fetching values

I have a file like this ############################################ # ParentFolder Flag SubFolders Colateral 1 Source1/Checksum CVA 1 Source1/Checksum Test 1 VaR/Checksum Test2 1 SVaR/Checksum FX 1 ... (6 Replies)
Discussion started by: manas_ranjan
6 Replies

8. Shell Programming and Scripting

help with fetching the values from perlscript

Hi, I have a perl script abc.pl.. #!/usr/bin/perl local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }else {... (3 Replies)
Discussion started by: puneetkanchi
3 Replies

9. Shell Programming and Scripting

fetching values using awk and storing into array

hi all I am using awk utility to parse the file and fetching two different vaues from two different record of a record set. I am able to see the result, now i want to store the result and perform some check of each values form database to mark valid and invalid. could you please help me... (3 Replies)
Discussion started by: singhald
3 Replies

10. UNIX Desktop Questions & Answers

Fetching unique values from file

After giving grep -A4 "feature 1," <file name> I have extracted the following text feature 1, subfeat 2, type 1, subtype 5, dump '30352f30312f323030392031313a33303a3337'H -- "05/01/2009 11:30:37" -- -- ... (1 Reply)
Discussion started by: shivi707
1 Replies
Login or Register to Ask a Question