|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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.
Last edited by zaxxon; 07-30-2010 at 03:25 AM.. |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Code:
$ awk -F "." '{print $2}' file1
Table_Name1
Table_Name2
Table_Name3
Table_Name4cheers, Devaraj Takhellambam |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
try Code:
awk -F "." '{print substr($2,0,index($2," "))}' file1or Code:
awk -F "." '{print $2}' file1 | awk '{print $1}'cheers, Devaraj Takhellambam |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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
|
|||
|
|||
|
Odd but Code:
$ awk -F "from " '{print substr($2,index($2,".")+1,index($2," ")-index($2,"."))}' file1cheers, Devaraj Takhellambam |
| The Following User Says Thank You to devtakh For This Useful Post: | ||
prasad4004 (07-30-2010) | ||
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|