I have a txt file with below data (textfile1.txt)
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
Table_Name1
Table_Name2
Table_Name3
Table_Name4
I have tried below command to pull Table_Name2 & 3
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.
$ awk -F "." '{print $2}' file1
Table_Name1
Table_Name2
Table_Name3
Table_Name4
cheers,
Devaraj Takhellambam
thanks Devaraj
Could you help me out to pull Table_Name alone without alias name
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
try
awk -F "." '{print substr($2,0,index($2," "))}' file1
or
awk -F "." '{print $2}' file1 | awk '{print $1}'
cheers,
Devaraj Takhellambam
Thanks Devaraj for your reply
Here i stuck up with one more issue, see below file contents there are alias for column names too
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
Odd but
$ awk -F "from " '{print substr($2,index($2,".")+1,index($2," ")-index($2,"."))}' file1
cheers,
Devaraj Takhellambam
1 Like