我试图找到一种使用Select并在文件中搜索精确匹配的方法,并在精确的colum中获取包含此精确匹配的所有行。数据文件中的示例片段:
08/25/2021 11:56:03 muzi.puzi 123 Bla
08/25/2021 19:56:03 bla.bla 1234 Bla
08/25/2021 19:56:03 abc.def 54 bla123Function Get_User_Dates_From_DBFile ([int] $Num, [string] $Db_File){
#Rereive all the dates in DataFile BiometricNum has signed on or off
$Dates = gc $Db_File | Select-String -Pattern "^$BioMetric_Num"
Return ($Date | Sort | Get-Unique)
}
Get_User_Dates_From_DBFile 123 $Db_file这将给我所有的三行,我想确保它没有捕获比这更多的东西(例如1234),并且确保它不会在最后一行的末尾捕获123,因为nubers只指第4行。
任何建议都会很好,谢谢
发布于 2021-08-25 15:47:38
我不知道你为什么在变量之前用屋顶标志.
但是这种模式会排除错误的123。
'08/25/2021 11:56:03 muzi.puzi 123 Bla
08/25/2021 19:56:03 bla.bla 1234 Bla
08/25/2021 19:56:03 abc.def 54 bla123' > file.txt
$BioMetric_Num = '123'
Get-Content .\file.txt | Select-String -Pattern " $BioMetric_Num "因此,在您的情况下,您的当前函数应该能够正确地使用
Get_User_Dates_From_DBFile ' 123 ' $Db_file
https://stackoverflow.com/questions/68903191
复制相似问题