?
Solved

pull string of words out of a file

Posted on 2011-10-04
9
Medium Priority
?
390 Views
Last Modified: 2012-05-12
I have an oracle trace file and want to pull the table name out of the file

FROM "table_name" is how it appears in the file.

I don't know if sed can do this I can't get awk to do this because the file wraps the text.
0
Comment
Question by:bkreynolds48
  • 5
  • 4
9 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 36910959
can you post your trace file?  or at least a snippet you're trying to parse?
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 36911080
Select BEG_VERSION, EXT_VERSION, FIRST_DATE, FIRST_USER, IND_CHANGE,
 INT_VERSION, I_PROJECT, LAST_DATE, LAST_USER, PROJECT_CODE, PROJECT_NAME,
 PRV_VERSION, V_LAST_DATE
FROM
 SNP_PROJECT where I_PROJECT = :1

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        9      0.00       0.00          0          0          0           0
Execute    823      0.02       0.02          0          0          0           0
Fetch      823      0.05       0.05          0       1646          0         823
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total     1655      0.08       0.08          0       1646          0         823

Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 100

Rows     Row Source Operation
-------  ---------------------------------------------------
 1  TABLE ACCESS BY INDEX ROWID SNP_PROJECT (cr=2 pr=0 pw=0 time=0 us cost=1 size=108 card=1)
 1   INDEX UNIQUE SCAN PK_PROJECT (cr=1 pr=0 pw=0 time=0 us cost=0 size=0 card
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 36911127
or it appears in the unformated file like....


Select BEG_VERSION, EXT_VERSION, FIRST_DATE, FIRST_USER, IND_CHANGE, INT_VERSION, I_PROJECT, LAST_DATE, LAST_USER, PROJECT_CODE, PROJECT_NAME, PRV_VERSION, V_LAST_DATE FROM SNP_PROJECT where I_PROJECT = :1

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 74

Expert Comment

by:sdstuber
ID: 36911145
which do you want to parse?

the trace file?
or the tkprof output?
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 36911176
the unformatted trace file

Select BEG_VERSION, EXT_VERSION, FIRST_DATE, FIRST_USER, IND_CHANGE, INT_VERSION, I_PROJECT, LAST_DATE, LAST_USER, PROJECT_CODE, PROJECT_NAME, PRV_VERSION, V_LAST_DATE FROM SNP_PROJECT where I_PROJECT = :1

0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 36911587
more robust parsing is outside the province of awk,  but this does a fair job for simple sql statements


awk 'BEGIN {foundparse=0}
/^PARSING IN CURSOR/ {foundparse=1}
/^END OF STMT/ {
   foundparse=0
   foundfrom=0
}
/[Ff][Rr][Oo][Mm]/{if (foundparse==1) foundfrom=1}
{
   if (foundfrom==1) {
      fromposition = match ($0, "[Ff][Rr][Oo][Mm]")
	  if (fromposition == 0) search = $0
      else search = substr($0,fromposition+4)
      wordcnt = split(search, words, "[ ,\t]+")
	  foundwhere=0
      for (i =1; i <= wordcnt && !foundwhere; i++) {
	     if (match(words[i],"[Ww][Hh][Ee][Rr][Ee]") > 0) foundwhere=1
	     else print words[i]
      }
   }
}' your_trace_file

Open in new window

0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 36911712
so how do I run this and capture the output?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 36911778
you run it on the command line exactly as presented

only change will be you use your own trace file's name where I have "your_trace_file"

0
 
LVL 1

Author Closing Comment

by:bkreynolds48
ID: 36911818
thanks much
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question