powershell - 如何在 PowerShell 中删除行范围
问题描述
我正在尝试删除多个文件范围。Mu文件包含1000行,我想在PowerShell中像这样删除第70-500行,第600-100行,
我试过-replace
了,但它不起作用。
尝试将行索引值 9 替换为 10:
(cat test.txt) -replace (cat test.txt)[9..10],"" | sc test.txt -Force
解决方案
使用ReadCount
属性Get-Content
添加到输出:
Get-Content 'test.txt' | Where-Object {
-not ($_.ReadCount -ge 70 -and $_.ReadCount -le 500) -and
-not ($_.ReadCount -ge 600 -and $_.ReadCount -le 1000)
}
推荐阅读
- azure - 如何将自定义日志转发到 Azure Sentinel
- php - PHP OAuth2 这里地图
- reactjs - 如何从笑话中调用 IntersectionObserver 回调函数?
- c# - 当通过 TCP 连接时,Mirth Connect 确实回复/回复
- swift - 如何在 iOS 14、Swift 5 中将状态栏的颜色更改为明暗以外的自定义颜色?
- google-apps-script - 使用脚本复制谷歌工作表,同时保留受保护工作表的权限
- mysql - 将 T-SQL 存储过程查询转换为 MySQL
- php - Fedex 上传文件 API
- javascript - 希望获得有关如何更有效地编写函数的反馈
- c++ - 为什么我需要使用双星号?**