Creating an sql statement from a file. Problem with '


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating an sql statement from a file. Problem with '
# 1  
Old 04-24-2008
Creating an sql statement from a file. Problem with '

Hi, I am trying to create sql statements from a file, but I have a problem with ':

This is what I do:
cat filex.txt | awk -F: '{print $1,"A","and personnavn like",$5}' | sed -e "s/^/select bruker.brukernavn, person.personnavn from bruker, person where brukernavn like '/" -e "s/$/' and bruker.person=person.id;/"

The output from this is:
select bruker.brukernavn, person.personnavn from bruker, person where brukernavn like 'xxx A and personnavn like XX XXXX' and bruker.person=person.id;

What I would like to have is:
select bruker.brukernavn, person.personnavn from bruker, person where brukernavn like 'xxx' and personnavn like 'XX XXXX' and bruker.person=person.id;

I am trying something like this:
cat filex.txt | awk -F: '{print $1,"\' and personnavn like \'",$5}' | sed -e "s/^/select bruker.brukernavn, person.personnavn from bruker, person where brukernavn like '/" -e "s/$/' and bruker.person=person.id;/"

But no ....
# 2  
Old 04-24-2008
Try this:

Code:
test ~ $ cat filex.txt
xxx:dummy:dummy:dummy:XX XXX

test ~ $ awk -F: -v v="'" '{ print("select bruker.brukernavn, person.personnavn from bruker, person where brukernavn like "v $1 v" and personnavn like "v $5 v" and bruker.person=person.id;"); }' filex.txt

# 3  
Old 04-24-2008
It worked! Smilie
Thank you. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating if statement for nfs

What would be correct syntax in a script to check to see if a /export/nfs/home mount point is mounted and if not stop/abort? OS is Solaris 10 using standard VI ksh shell. Here is the script. Please tell me where you see the problem. #!/bin/bash # # This script is run as root to sync AMI PROD... (0 Replies)
Discussion started by: soupbone38
0 Replies

2. UNIX for Dummies Questions & Answers

Problem in creating CSV file

Hi guys, I am not experienced with Unix, so please dont mind if the question seem to be irrelevant. I have written a simple script, that connects DB & fetches few records from a table. I wanted to get those details as file in .CSV format via mail. -I stored the query o/p in a file. -I... (6 Replies)
Discussion started by: sumitburnwal88
6 Replies

3. UNIX for Dummies Questions & Answers

unix script with SQL statement problem

Hello, I have a script to get the information from database, however, it's look like the loop is not work, can someone help? :confused: echo Input file list to check: read filelist for file in 'cat $filelist.txt' do echo "select FILENAME from FILE_TABLE where filename like '${file}'%;" >>... (9 Replies)
Discussion started by: happyv
9 Replies

4. Shell Programming and Scripting

problem in creating my own profile file in unix

I am new in shell scripting. currently i am using cygwin. My problem is i created a profile file in my own folder. file name is first.profile in which i gave following values to variable export a=10 now i am executing this profile file by below command ./.first.profile it executed... (4 Replies)
Discussion started by: pratikjain998
4 Replies

5. Shell Programming and Scripting

Execute and log each statement/block SQL file

Hi friends, I would like to get some help on the following requirement. I have a SQL file with following things, select 1 from dual; select user from dual; select sysdate from dual; BEGIN PL/SQL Code END; / This file will be saved as sql file. When I run my expected shell script,... (1 Reply)
Discussion started by: ssnair
1 Replies

6. Shell Programming and Scripting

Problem creating file with awk

Hello, I don't understand why the script below doesn't act the way it should : #!/bin/sh awk 'BEGIN{printf("Entrez la date : "); getline date < "-"} $0 ~ date {f=1;print;next} /^{2}\//{f=0} f' Planning.csv > planning.txt It doesn't create file planning.txt with only the result of... (14 Replies)
Discussion started by: freyr
14 Replies

7. Shell Programming and Scripting

Executing sql statement from .sh file

Hi, How to execute sql statements from the .sh file ?? Means, when we run .sh file then the sql statements within it should be get executed one by one from the sqlplus With Regards (3 Replies)
Discussion started by: milink
3 Replies

8. Shell Programming and Scripting

Creating a .sh script to execute an SQL file

Hello I'm hoping someone may be able to help. I'm absolutely brand new to these shell scripts and have tried to bash bits together from the little learnt but my final script still doesn't work. Sorry if something similar is already posted but couldn't find anything existing close enough to help... (1 Reply)
Discussion started by: Dan27
1 Replies

9. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

10. HP-UX

SQL statement output to Log file-How?

Hi all, I need to bring the message to log file.Teradat/Hp-Ux script: ----- ### Update Log Table bteq <<- EOC .run file ${SRC_DATA}/logon.txt .run file ${SRC_DATA}/dbstagebteq.txt .set format off .set foldline off all .set sidetitles off ... (1 Reply)
Discussion started by: vsubbu1000
1 Replies
Login or Register to Ask a Question