To read the values and to use in the where condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To read the values and to use in the where condition
# 1  
Old 08-11-2010
To read the values and to use in the where condition

Hi,

I have the below values in a text file.

Code:
'xx.16397950',
'xx.16397957',
'xx.16397976',
'xx.16473259',

I need to use in the where clause of the sql query in my unix shell script. How to read one by one value.

It should be like this:

Code:
select * from <<table name>> where xx in ( the above values )

Please guide.

Many thanks in advance.
# 2  
Old 08-11-2010
Hi,

try this,
Code:
xx_value=`paste -s inputfile| sed 's/,$//g'`
echo "select * from <<table name>> where xx in ( $xx_value )"

# 3  
Old 08-11-2010
Giving the below error:

Code:
xx_value: command not found

I'm using Linux and executing the script like below:

Code:
./<<name of the script>> <<argument>>

# 4  
Old 08-11-2010
Post your code. What argument are you passing to script.
# 5  
Old 08-11-2010
Below is the code

Code:
#!/bin/bash
read shipments
sort shipments | uniq > test1.txt
sed "s/.*/'TT.&',/;$ s/,//" test1.txt > output
value = `paste -s output`
echo "select * from tn where xx in ($value)"

Executed as below:

Code:
./xx shipments

# 6  
Old 08-11-2010
Hi

The error is because you have a space before and after =. Remove the spaces.

Code:
value=`paste -s output`

Guru.
# 7  
Old 08-11-2010
One more suggestion , Instead of creating output file, you can pipe the output to paste command as follow.
Code:
#!/bin/bash
read shipments
sort shipments | uniq > test1.txt
value=`sed "s/.*/'TT.&',/;$ s/,//" test1.txt | paste -s`
echo "select * from tn where xx in ($value)"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add the values of the lines according to a condition

hi everybody :) I am a beginner in bash and I want to convert the result I have here I want it to be grouped by IP address so iwanna get for each ip adsress the addition of all bandwidth where ip is 100.1.1.15 in other words for 100.1.1.15 it groups me all the values whose ip address is... (11 Replies)
Discussion started by: aynar
11 Replies

2. Shell Programming and Scripting

Remove duplicate values with condition

Hi Gents, Please can you help me to get the desired output . In the first column I have some duplicate records, The condition is that all need to reject the duplicate record keeping the last occurrence. But the condition is. If the last occurrence is equal to value 14 or 98 in column 3 and... (2 Replies)
Discussion started by: jiam912
2 Replies

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

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 column from file and delete rows with some condition..

Hi.... I have a need of script to do delete row whenever condition is true.... 2.16 (3) 1 3 9999 0 (1) (0) 34.42 (4) 1 3 9999 37 (2) (3) 34.38 (4) 1 3 9999 64 (2) (3) 34.4 (4) 1 3 1 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

6. Shell Programming and Scripting

Read 2 files alternatively based on condition.

Experts, What would be the code in ksh/perl to read 2 files alternatively, based on the following condition. while reading file 1 we check if a blank line is encountered, if yes, then we read file 2 unless a blank line is encountered in file 2 if we have a blank line in file 2 we come back... (3 Replies)
Discussion started by: suraj.sheikh
3 Replies

7. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

8. Shell Programming and Scripting

Read file based on condition

Hi Friends, Can any one help with this: I have a huge file with the format as A SAM 4637 B DEPT1 4758 MILAN A SMITH 46585 B DEPT2 5385 HARRYIS B SAMUL 63547 GEORGE B DANIEL 899 BOISE A FRES 736 74638 I have to read this file and write only the records that starts with "B" only ... (5 Replies)
Discussion started by: sbasetty
5 Replies

9. Shell Programming and Scripting

Can't use 'read' in 'if-condition'

Hi, I'm having this problem, it seems that I can't read a value in an if-condition. First line of my script "#!/bin/ksh" Now if I do the following, for some kind of reason he does skip the 'read go_on', I'm not able to give input when he executes this, he just goes on executing the script.... (2 Replies)
Discussion started by: lumdev
2 Replies

10. Shell Programming and Scripting

need to read a file and keep waiting till it satisfies some condition

In my script i am writing to a counter file the no of processes i had started, that is each time i start a process, i will increment the content of counter file and also when the process ends i will decrement the content of the file. after this i do some other activities, by now i want to... (1 Reply)
Discussion started by: senthilk615
1 Replies
Login or Register to Ask a Question