how to write 2 variables while using read command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to write 2 variables while using read command
# 1  
Old 10-21-2009
how to write 2 variables while using read command

Hello All

i have input files contains 2 values as following
20-Oct-09 Z59408009
20-Oct-09 Z59423060

and i am using the following script

cat /home/or/input.txt | awk '{print $2}' >log
count=0
while read line; do
count=$(( count + 1 ))
echo "UPDATE SAT_JRLTRT SET AVT='X' WHERE IDTTRX='$line' AND DATDDE=to_date('$line2','DD/MM/YYYY');" >>log1
done < log


but i need to add the above 2 values 20-Oct-09 Z59423060 and the script add one value only

any idea how it could be done

regards
# 2  
Old 10-21-2009
Code:
while read DATE STRING; do
echo "UPDATE SAT_JRLTRT SET AVT='X' WHERE IDTTRX='$STRING' AND DATDDE=to_date('$DATE','DD/MM/YYYY');" >>log1
done < /home/or/input.txt

# 3  
Old 10-21-2009
Quote:
Originally Posted by scottn
Code:
while read DATE STRING; do
echo "UPDATE SAT_JRLTRT SET AVT='X' WHERE IDTTRX='$STRING' AND DATDDE=to_date('$DATE','DD/MM/YYYY');" >>log1
done < /home/or/input.txt

Thanks for help

but i dont wants machine date , i need the date in the file ?

regards
# 4  
Old 10-21-2009
That is the date in the file.

Code:
while read DATE STRING; do
...
done < /home/or/input.txt

In any case the date in your file ('DD-MMM-YYYY') doesn't match the pattern in you update ('DD/MM/YYYY')
# 5  
Old 10-21-2009
Quote:
Originally Posted by scottn
Code:
while read DATE STRING; do
echo "UPDATE SAT_JRLTRT SET AVT='X' WHERE IDTTRX='$STRING' AND DATDDE=to_date('$DATE','DD/MM/YYYY');" >>log1
done < /home/or/input.txt

Smilie i am sorry i thought it was machine date ,, it works fine as i can see

---------- Post updated at 04:50 PM ---------- Previous update was at 04:49 PM ----------

Quote:
Originally Posted by scottn
That is the date in the file.

Code:
while read DATE STRING; do
...
done < /home/or/input.txt


man thanks man it workssssssss

what if i have another string ?
# 6  
Old 10-21-2009
Then

Code:
while read DATE STRING; do

becomes

Code:
while read DATE STRING ANOTHER_STRING; do

# 7  
Old 10-21-2009
Quote:
Originally Posted by scottn
Then

Code:
while read DATE STRING; do

becomes

Code:
while read DATE STRING ANOTHER_STRING; do

man i realy apricate your deep help many thankSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read several variables from command output via SSH

Hi Folks, I'm currently trying to read several values into different variables. Actually, what I'm doing works, but I get an error message. My attempts are: read strCPROC strIPROC strAPROC <<<$(ssh -n -T hscroot@$HMC "lshwres -r proc -m $strIDENT --level sys -F \"configurable_sys_proc_units... (11 Replies)
Discussion started by: NKaede
11 Replies

2. Shell Programming and Scripting

How can I write variables to same line of a file?

I am trying to keep variables in a file. if I have all variables at the same time, I can write them all like below. echo $var1","$var2","$var3 But, these variables are being calculated at different times then they are lost so I want to keep them in a file seperated by "," . echo... (5 Replies)
Discussion started by: snr_silencer
5 Replies

3. Shell Programming and Scripting

Write string variables to file

I have the following: #! /bin/bash foo="bar" this="that" vars="foovar=$foo\n\ thisvar=$this\n" I want to write the following to a file: foovar="bar" thisvar="that" Then in another script, I pull this file, and loop through it: while read line; do eval $line done <... (3 Replies)
Discussion started by: Validatorian
3 Replies

4. Shell Programming and Scripting

How do write using variables

Hello Team, I have the following line in a .sh file .That means if we add my file.sh file to crontab .The crontab will read the first line where the db2 profile is installed.Can some body help me how to recode this using a variable ? That means the below path is static to a perticular... (3 Replies)
Discussion started by: rocking77
3 Replies

5. Shell Programming and Scripting

Environment Variables in text file and read command

I cannot get the following substitution ($ORACLE_SID) to work: The variable ORACLE_SID is set to wardin my environment. It has been exported. I have a text file called test.dat: /u07/oradata/${ORACLE_SID}/extab/finmart/summit/ps_voucher_line_crnt_ex.dbf... (2 Replies)
Discussion started by: bradyd
2 Replies

6. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

7. Shell Programming and Scripting

Interpreting Logicals/Environment Variables using the read command

Hi All I have something that from the outset seems really trivial but in practice is not quite working. I have the following code sample in my shell script which illustrates the problem echo "enter home directory" read home mkdir $home/newdir The user then enters a logical $HOME... (3 Replies)
Discussion started by: kingpin2502
3 Replies

8. Shell Programming and Scripting

Find all files with group read OR group write OR user write permission

I need to find all the files that have group Read or Write permission or files that have user write permission. This is what I have so far: find . -exec ls -l {} \; | awk '/-...rw..w./ {print $1 " " $3 " " $4 " " $9}' It shows me all files where group read = true, group write = true... (5 Replies)
Discussion started by: shunter63
5 Replies

9. UNIX for Dummies Questions & Answers

trouble using read to store values in variables from command output

I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie. I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me. ... (2 Replies)
Discussion started by: ProGrammar
2 Replies

10. Shell Programming and Scripting

SED command for read and write to different files

Hi I need some help on SED command I am writing a shell script which does the following: 1. Read one line at a time from a file abc.txt which has millions of lines 2. Prefix each line read with some text " 3. Post fix each line read with a quote " 4. Write the new modified... (11 Replies)
Discussion started by: gaurav_1711
11 Replies
Login or Register to Ask a Question