Hunter的大杂烩 技术学习笔记

2025-06-01

windows下查找两个文件相同字符串的powershell脚本

Filed under: 技术话题 — hunter @ 12:32 am

# 查看当前区域设置
Get-Culture

# 设置区域设置为中文(简体)
$PSDefaultParameterValues[‘*:Encoding’] = ‘utf8’
[System.Globalization.CultureInfo]::DefaultThreadCurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo(“zh-CN”)
[System.Globalization.CultureInfo]::DefaultThreadCurrentUICulture = [System.Globalization.CultureInfo]::GetCultureInfo(“zh-CN”)

Get-Content 1.txt | ForEach-Object {
$pattern = [regex]::Escape($_.Trim())
if (Select-String -Path 2.txt -Pattern “$pattern”) { $_ }
} | Sort-Object -Unique | Set-Content common_files.txt



No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress