【发布时间】:2019-06-18 15:50:36
【问题描述】:
我有近 400 个 .sql 文件,我需要在其中搜索特定模式并输出结果。
例如
*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>
预期结果
file1.sql mydb.ops1_tbl
file2.sql mydb.ops2_tbl
file3.sql mydb.ops3_tbl mydb.ops4_tbl
powershell 中的以下脚本 - 能够获取文件名
Get-ChildItem -Recurse -Filter *.sql|Select-String -pattern "mydb."|group path|select name
powershell 中的以下脚本 - 能够获取行
Get-ChildItem -Recurse -Filter *.sql | Select-String -pattern "mydb." |select line
我需要上述格式,有人对此有任何指示吗?
【问题讨论】:
标签: regex powershell scripting