[Solved] Using AWK to extract SQL result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Using AWK to extract SQL result
# 1  
Old 09-24-2012
[Solved] Using AWK to extract SQL result

Quote:
nawk '/data/, /SQL/ {if ($0 ~ /SQL/) {} else {print;}}' /tmp/$resultEqpt_dir >> /tmp/$resultEqpt_dir.out
I just wish to extract the result onli... but I dont which edit to perform to start from (**) Smilie
Current display result
Code:
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Sep 24 14:14:49 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
 
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, Data Mining and Real Application Testing options
 
Session altered.
SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12 13 (**)TFM021,2012-09-24 12:18:28,LOGON,TH19_6
TFM030,2012-09-24 10:29:46,LOGOFF,TH20_6
TFM034,2012-09-24 12:50:09,LOGON,TH19_34
TFM041,2012-09-24 07:25:10,LOGON,TD10_5
TFM043,2012-09-23 19:21:11,LOGOFF,TB15_0


Last edited by radoulov; 09-24-2012 at 05:52 AM..
# 2  
Old 09-24-2012
try this..

Code:
sed '1,/SQL> SQL> SQL>/d' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 09-24-2012
Quote:
Originally Posted by pamu
try this..

Code:
sed '1,/SQL> SQL> SQL>/d' file

Quote:
TTT225,2012-09-24 15:02:13,LOGON,TC09_16
SQL> SQL> SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, Data Mining and Real Application Testing options
i have the btm for this how wld i remove the btm till EOF..

sed 'SQL> SQL> SQL> D, eof? d' file ??
# 4  
Old 09-24-2012
try this..

Code:
sed -n '/SQL> SQL> SQL>/,/SQL> SQL> SQL>/p' file

# 5  
Old 09-24-2012
Quote:
Originally Posted by pamu
try this..

Code:
sed '1,/SQL> SQL> SQL>/d' file

any it removed the whole line and also had removed my first data

---------- Post updated at 04:06 PM ---------- Previous update was at 03:39 PM ----------

thanks! Problem resolved

Solution is:
I applied

Quote:
sed '1,16 d' </tmp/$resultEqpt_dir >/tmp/$resultEqpt_dir.out
sed -n -e :a -e '1,5!{P;N;D;};N;ba' </tmp/$resultEqpt_dir.out >/tmp/resultEqpt.log
calc the no. of lines to remove

[closed]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get SQL query result to file in putty

How to Get SQL query result to file in putty? I have one SQL query and I want that query output to be redirected to the file. uname -a SunOS XXX 5.8 Generic_117350-58 sun4u sparc SUNW,Sun-Fire-480R Please suggest. (7 Replies)
Discussion started by: pamu
7 Replies

2. Shell Programming and Scripting

[Solved] My sed command not give me a satisfy result

This is my command echo "Test" | sed -f <(sed -e 's/.*/s,&,gI/' mydic) In mydic file,containing 2 columns delimit by comma (,) a,AlphabetA . . . e,AlphabetE . . s,AlphabetS . t,AlphabetT test,testedd . . zebra,zebraaaa The expect result is testedd (0 Replies)
Discussion started by: Runicer
0 Replies

3. UNIX for Dummies Questions & Answers

Assign SQL result in shell variable

Hi im trying to assign the result of the db2 command to a variable inside a shell script... : tab_cnt=`db2 "select count(*) from syscat.tables where tabname = 'ABC' and tabschema = 'MATT01'" |head -4|tail +4|cut -c 11` : echo $tab_cnt when i echo im getting a blank value.. im expecting... (1 Reply)
Discussion started by: matt01
1 Replies

4. UNIX for Advanced & Expert Users

Output the SQL Query result to a File

Hello Guys, This message is somewhat relates with last thread. But I need to re-write thing. I start over a little. I am stuck now and need your help. Here is my script- #! /bin/ksh export ORACLE_HOME=/opt/oracle/app/oracle/product/9.2 /opt/oracle/app/oracle/product/9.2/bin/sqlplus -s... (5 Replies)
Discussion started by: thepurple
5 Replies

5. Shell Programming and Scripting

Sending one email for every row as per sql result

I want to send email for every row comes out of following SQL statement thank you for your help. *****SQL STATEMENT****** Select SCUSER AS "USER IDS" , SCEUSER AS "LOCKED OUT" FROM SYS.7333.F98OWSEC; *******OUPUT COMES LIKE THIS AND ONE EMAIL COMES AS PER SCRIPT BELOW****** ******BUT... (4 Replies)
Discussion started by: s1a2m3
4 Replies

6. Shell Programming and Scripting

How to Format the result driven from a SQL Query

Hi All, I want to format the result driven from the query into neat format. For example pls find the below code, #! /bin/sh result=' sqlplus -s uname/passwrd@DBname select no,name,address,ph_no, passport_no,salary,designation from emp_table where salary>1000; exit EOF' ... (8 Replies)
Discussion started by: little_wonder
8 Replies

7. UNIX for Dummies Questions & Answers

Grabbing result of sql command

Hi guys, Is there a way a script can run an SQL statement and dump the results into a variable which can then be used later in the script? Thanks. (3 Replies)
Discussion started by: hern14
3 Replies

8. Shell Programming and Scripting

formatting the sql select result

Hi, I have about 12 columns and 15 rows to be retrived from sybase isql command through unix. But when i output the sql into a file and see it, the formatting is going for a toss. can someone please suggest how can i get the result correctly in the output file ? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies

9. Shell Programming and Scripting

any possible to run sql result and output to file

Hi, I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file. for example, i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this... (7 Replies)
Discussion started by: happyv
7 Replies

10. Shell Programming and Scripting

how to retrieve sql result to unix....

Hi, i would like to retrieve seql result and write it into unix text file like "result.txt" In unix, normally, I type "sql" and get into sql,then type "select....." to run and get the result....then copy and paste into result.txt any possible way to write a script to run it automatically?... (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question