|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to take input from two files in a UNIX script?
I have a simple script which returns me the response from a table. Code:
while read -r xx do db2 -x "select * from Table where user ='$xx' with ur " >> "/home/Results.txt" done < "/home/USERS.txt" Now I want to have two different clause in the where clause and want the script to take input from two files or same file with delimiters ...how do I input the yy variable value to the query below ??????? Code:
do db2 -x "select * from Table where user ='$xx' and client = '$yy' with ur " >> "/home/Results.txt" done < "/home/USERS.txt" Last edited by Corona688; 03-14-2013 at 01:11 PM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Same file with delimiters: Code:
while IFS="," read VAR1 VAR2 THEREST
do
...
done < inputfileTwo files: Code:
exec 5<file1 # Open file into FD 5
exec 6<file2
while read VAR1 <&5 && read VAR2 <&6
do
...
done
exec 5<&- # Close FD 5
exec 6<&-One file would obviously be preferable. Also, you don't need to reopen Results.txt 9,000 times to write 9,000 lines to it. You can redirect the output of your loop the same way you redirect its input. Code:
while ... do ... done > results.txt |
| The Following User Says Thank You to Corona688 For This Useful Post: | ||
Sanjeev Yadav (03-14-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Sanjeev,
You have posted the same question to two different forums and received different answers to your posts. You shouldn't post to multiple locations because the responses to your posts will likely not realize that two conversations are going on for this single topic. Please don't do this again in the future. Please ask the administrators to merge these two discussions into a single thread and to close the other one! |
|
#4
|
|||
|
|||
|
I tried running the below script but it doesn't work for me....can you fix this for me....Sorry, I am new to unix.. Code:
exec 5< "/home/epprod/COSMOS_CUSTOME_CLIENTID.txt" exec 6< "/home/epprod/COSMOS_CUSTOME_CLIENTIDS.txt" while read VAR1 <&5 && read VAR2 <&6 do db2 -x "select customer_nbr,client_id from policies where customer_nbr='VAR1' and client_id='VAR2' with ur " >> "/home/epprod/COSMOS_CUSTOME_CLIENTID_Results.txt" done exec 5<&- exec 6<&- Last edited by Corona688; 03-14-2013 at 02:21 PM.. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
You are one infraction away from being set read-only for a while, please listen to the messages and warnings we're giving you. Don't double-post, be sure to code-tag your posts, and do NOT pm people with technical questions or to 'hurry them up'. We are not on call. Code:
while read VAR1 <&5 && read VAR2 <&6 do db2 -x "select customer_nbr,client_id from policies where customer_nbr='$VAR1' and client_id='$VAR2' with ur " done > "/home/epprod/COSMOS_CUSTOME_CLIENTID_Results.txt" |
| Sponsored Links | ||
|
![]() |
| Tags |
| sql, unix |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help in unix script to join similar lines of input | rei125 | Shell Programming and Scripting | 3 | 06-29-2012 03:55 AM |
| Script to delete files with an input for directories and an input for path/file | *ShadowCat* | Shell Programming and Scripting | 3 | 06-28-2012 09:16 PM |
| How to get this script work on multiple input files | Daniel8472 | Shell Programming and Scripting | 9 | 08-28-2010 08:43 AM |
| Write a new file from 2 files as input to the script | sniper57 | Shell Programming and Scripting | 5 | 06-11-2009 05:14 AM |
| Script to find files on a given input date | ar.karan | Shell Programming and Scripting | 1 | 08-13-2007 10:07 PM |
|
|