Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在文件中搜索模式_Powershell_Csv - Fatal编程技术网

Powershell 在文件中搜索模式

Powershell 在文件中搜索模式,powershell,csv,Powershell,Csv,如何在文件中搜索用分号分隔的精确字符串 比如:username;暗语出生日期 因此,我可以列出2000年之前出生的用户?使用Import-Csvcmdlet,并使用Where-Objectcmdlet对其进行筛选: Import-Csv 'your_csv_file' -Delimiter ';' | Where {($_.birthdate -split '\.')[0] -le 2000} 由于这看起来像CSV,如果您提供一个示例,我们可能会为您提供一个比使用e更好的解决方案。G

如何在文件中搜索用分号分隔的精确字符串

比如:
username;暗语出生日期


因此,我可以列出2000年之前出生的用户?

使用
Import-Csv
cmdlet,并使用
Where-Object
cmdlet对其进行筛选:

Import-Csv 'your_csv_file' -Delimiter ';' | 
    Where {($_.birthdate -split '\.')[0] -le 2000}

由于这看起来像CSV,如果您提供一个示例,我们可能会为您提供一个比使用e更好的解决方案。G
Select-String
cmdlet。您可以使用get-content并在每一行中循环文件。然后使用-match并构建一个-但也许您最好使用importcsv并在foreach中实现它。并通过$检查生日。生日…py504n;暗语1997.12.27;是的,一个foreach可能很好:D感谢您的想法,必须添加输入CSV,它需要与列匹配的标题,或者您需要使用
-headers“username”、“password”、“birthdate”指定
导入CSV
的标题