pull string of words out of a file

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.
LVL 1
bkreynolds48Asked:
Who is Participating?
 
sdstuberCommented:
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
 
sdstuberCommented:
can you post your trace file?  or at least a snippet you're trying to parse?
0
 
bkreynolds48Author Commented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
bkreynolds48Author Commented:
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
 
sdstuberCommented:
which do you want to parse?

the trace file?
or the tkprof output?
0
 
bkreynolds48Author Commented:
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
 
bkreynolds48Author Commented:
so how do I run this and capture the output?
0
 
sdstuberCommented:
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
 
bkreynolds48Author Commented:
thanks much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.