How to get the SQL CODE from a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the SQL CODE from a file?
# 1  
Old 06-26-2011
How to get the SQL CODE from a file?

Hi Guys Smilie

need your help once again

I have some files from which I have to fetch the SQL CODE which in anywhere in file. please help me

input files : file1 :
Code:
 ERROR ON SECTION : 2060-GET-OTHER-DEP-INFO
 ERR MSG : ERROR IN FETCH MCURS
 SQL CD :  100   SUBS ID : 153687143

input files : file2 :
Code:
 ERR MSG : ERROR IN FETCH MCURS
  SUBS ID : 153687143  SQL CD :  100

I tried this code line
Code:
grep ' SQL CD :' filename

which gave me the line which have the SQL code, but dont know how to extract the SQL CD value because SQL CD value exist anywhere in file.

Help me

thanks
Atul
# 2  
Old 06-26-2011
Try this:
Code:
grep 'SQL CD' infile | sed -r 's/.*SQL CD : *([0-9]*).*/\1/'

This User Gave Thanks to tukuyomi For This Post:
# 3  
Old 06-26-2011
thanks man

worked !!!

thanks
Atul Singh
# 4  
Old 06-27-2011
Avoid grep by using..
Code:
sed -rn 's/.*SQL CD : *([0-9]*).*/\1/p' inputfile > outfile

# 5  
Old 06-27-2011
Hi michael

can you please explain the command. I am learning SED.. Smilie

thanks
Atul
# 6  
Old 06-27-2011
The sed command posted is same as what tukuyomi posted except for -n and p which helps to output only the line which matches the pattern (SQL CD). If unclear try running the below two sed commands and check
Code:
sed -rn 's/.*SQL CD : *([0-9]*).*/\1/p' inputfile > outfile
sed -r 's/.*SQL CD : *([0-9]*).*/\1/' inputfile > outfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Code needed to get sql queries

Hi i need code to get sql queries through a shell script for a text file input which contain the service ids iputfile I-H-2048-10GB-M I-H-4096-12GB-M I-H-2048-p1000-M the code should contain below queries among which service_id is replacable with value from input file. ... (4 Replies)
Discussion started by: surender reddy
4 Replies

2. Shell Programming and Scripting

Spotting lowercase SQL code

We want to check where our programmers are using lowercase SQL reserved words, ie "select" instead of "SELECT". Obviously, we should not raise a warning for code which is commented out with "//". Suppose I have this input: select * from mytable SELECT * from mytable // select * from mytable... (2 Replies)
Discussion started by: figaro
2 Replies

3. UNIX for Advanced & Expert Users

How to Make Sql Plus Exit with an Error Code

Dear all, How to make sqlplus command to exit with an apt error code in bash script, It always returns 0 for me. Thanks (9 Replies)
Discussion started by: vetrivendhan
9 Replies

4. Shell Programming and Scripting

html code in SQL query

Hi expert, I have a script which is connecting with sql internally, fetch same data, store it in a file and then from os I cat this file and sending it to mail (windows outlook). This is working fine, I just need to know wether we can add some html codes with the sql query like we can add... (0 Replies)
Discussion started by: mcagaurav
0 Replies

5. Shell Programming and Scripting

How to use sql data file in unix csv file as input to an sql query from shell

Hi , I used the below script to get the sql data into csv file using unix scripting. I m getting the output into an output file but the output file is not displayed in a separe columns . #!/bin/ksh export FILE_PATH=/maav/home/xyz/abc/ rm $FILE_PATH/sample.csv sqlplus -s... (2 Replies)
Discussion started by: Nareshp
2 Replies

6. UNIX for Dummies Questions & Answers

Execute PL/SQL function from Unix script (.sql file)

Hi guys, I am new on here, I have a function in oracle that returns a specific value: create or replace PACKAGE BODY "CTC_ASDGET_SCHED" AS FUNCTION FN_ASDSCHEDULE_GET RETURN VARCHAR2 AS BEGIN DECLARE ASDSchedule varchar2(6); ASDComplete... (1 Reply)
Discussion started by: reptile
1 Replies

7. Shell Programming and Scripting

SQL code into a variable.

Hi, Iam new to unix. Is there any way to get the sql code "ORA-01847" into a variable. sqlplus username/password@database name << EOF set heading off update TempTable set variable where condition; exit sql.sqlcode; commit; exit; EOF Output ERROR at line 1: ORA-01847: day of... (1 Reply)
Discussion started by: manneni prakash
1 Replies

8. Shell Programming and Scripting

conditional writing of sql code

Hello again... I have a request from another department to list for them all the columns and tables we use in this certain database. I have spooled the oracle stored procedured into 1 file. I need a way to write out parts of that file. The criteria is to to start the block to be written when... (0 Replies)
Discussion started by: kburrows
0 Replies

9. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies

10. Shell Programming and Scripting

sql error code trapping

Hello #!bin/ksh sqlplus -s system/manager < |grep '^ORA' |uniq select * from kk; set echo on show spool on end; / EOF save test.sh sh test.sh results ORA-00942: table or view does not exist (3 Replies)
Discussion started by: xiamin
3 Replies
Login or Register to Ask a Question