Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

search pattern and extract from file using powershell

$
0
0

I have almost 400 .sql files where i need to search for a specific pattern and output the results.

e.g

*file1.sql

select * from mydb.ops1_tbl from something1 <other n lines>

*file2.sql

select * from mydb.ops2_tbl from something2 <other n lines>

*file3.sql

select * from mydb.ops3_tbl ,mydb.ops4_tbl where a = b <other n lines>

expected result

file1.sql mydb.ops1_tbl

file2.sql mydb.ops2_tbl

file3.sql mydb.ops3_tbl mydb.ops4_tbl

Below script in powershell - able to fetch the filname

Get-ChildItem-Recurse-Filter*.sql|Select-String-pattern "mydb."|group path|select name

Below script in powershell - able to fetch the line

Get-ChildItem-Recurse-Filter*.sql |Select-String-pattern "mydb."|select line

I need in the above format, someone has any pointer?


Rakesh Jayaram http://blogs.msdn.com/b/rakesh_ramblings/


Viewing all articles
Browse latest Browse all 935

Trending Articles