Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-30-2010
Registered User
 

Join Date: Jul 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
How to retrieve data using awk command

I have a txt file with below data (textfile1.txt)

Code:
select col1, col2 from Schema_Name.Table_Name1
select * from Schema_Name.Table_Name2
select col1, col2, col3 from Schema_Name.Table_Name3
select col1 from Schema_Name.Table_Name4

My output should look like

Code:
Table_Name1
Table_Name2
Table_Name3
Table_Name4

I have tried below command to pull Table_Name2 & 3

Code:
cat textfile1.txt |awk -F "Schema_Name| " '{split($3,v,".");print v[2]}'

Could anyone help me out to pull all table names irrespective of where it appears in a select statement.

Moderator's Comments:
Use code tags please, ty.

Last edited by zaxxon; 07-30-2010 at 03:25 AM..
Sponsored Links
    #2  
Old 07-30-2010
devtakh devtakh is offline Forum Advisor  
Unix Enthusiatic
 

Join Date: Oct 2007
Location: Bangalore
Posts: 730
Thanks: 0
Thanked 6 Times in 6 Posts

Code:
$ awk -F "." '{print $2}' file1
Table_Name1
Table_Name2
Table_Name3
Table_Name4


cheers,
Devaraj Takhellambam
Sponsored Links
    #3  
Old 07-30-2010
Registered User
 

Join Date: Jul 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
thanks Devaraj

Could you help me out to pull Table_Name alone without alias name

Code:
select col1, col2 from schema_Name.Table_Name1 a
select * from schema_Name.Table_Name2 b
select col1, col2, col3 from schema_Name.Table_Name3 c
select col1 from schema_Name.Table_Name4 d


Last edited by zaxxon; 07-30-2010 at 03:25 AM.. Reason: code tags
    #4  
Old 07-30-2010
devtakh devtakh is offline Forum Advisor  
Unix Enthusiatic
 

Join Date: Oct 2007
Location: Bangalore
Posts: 730
Thanks: 0
Thanked 6 Times in 6 Posts
try

Code:
awk -F "." '{print substr($2,0,index($2," "))}' file1

or


Code:
awk -F "." '{print $2}' file1 | awk '{print $1}'

cheers,
Devaraj Takhellambam
Sponsored Links
    #5  
Old 07-30-2010
Registered User
 

Join Date: Jul 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks Devaraj for your reply

Here i stuck up with one more issue, see below file contents there are alias for column names too

Code:
select col1, col2 from schema_Name.Table_Name1 a
select * from schema_Name.Table_Name2 b
select c.col1, c.col2, c.col3 from schema_Name.Table_Name3 c
select d.col1 from schema_Name.Table_Name4 d

Sponsored Links
    #6  
Old 07-30-2010
devtakh devtakh is offline Forum Advisor  
Unix Enthusiatic
 

Join Date: Oct 2007
Location: Bangalore
Posts: 730
Thanks: 0
Thanked 6 Times in 6 Posts
Odd but

Code:
$ awk -F "from " '{print substr($2,index($2,".")+1,index($2," ")-index($2,"."))}' file1

cheers,
Devaraj Takhellambam
The Following User Says Thank You to devtakh For This Useful Post:
prasad4004 (07-30-2010)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Retrieve data and redirect to a file anupdas UNIX for Advanced & Expert Users 2 01-18-2010 12:42 AM
how to retrieve only the Use% value from df command codeman007 Shell Programming and Scripting 8 09-23-2008 02:17 AM
to find header in Mp3 file and retrieve data shashi Programming 2 09-12-2008 03:03 AM
Retrieve data from a file tpltp Shell Programming and Scripting 2 03-28-2008 04:36 AM
How to retrieve the typed command laum UNIX for Dummies Questions & Answers 5 07-15-2005 01:10 AM



All times are GMT -4. The time now is 04:01 AM.