Powershell 删除文本文件中的行
导出或删除特定行。我的大文本文件(结构:日期、url、标题): 2018-11-23 15:03:06;$https://super.cz;$超级cz 2018-11-26 14:09:06;$https://novinky.cz;$诺文基 2018-11-26 15:13:06;$https://denik.cz;$ 2018-11-27 08:06:13;$https://www.google.com;$古戈尔 等 所需的文本文件结构(删除第三行和其他行): 2018-11-23 15:03:06;$https://super.cz;$超级cz 2018-11-26 14:09:06;$https://novinky.cz;$诺文基 2018-11-27 08:06:13;$https://www.google.com;$古戈尔 等Powershell 删除文本文件中的行,powershell,Powershell,导出或删除特定行。我的大文本文件(结构:日期、url、标题): 2018-11-23 15:03:06;$https://super.cz;$超级cz 2018-11-26 14:09:06;$https://novinky.cz;$诺文基 2018-11-26 15:13:06;$https://denik.cz;$ 2018-11-27 08:06:13;$https://www.google.com;$古戈尔 等 所需的文本文件结构(删除第三行和其他行): 2018-11-23 15:03
只需读取文件并删除以
结尾的行$代码>,然后将修改后的内容写回文件
$file = 'C:\path\to\your.csv'
(Get-Content $file) | Where-Object {
$_ -notlike '*;$'
} | Set-Content $file
请注意,Get Content
调用周围的括号在这里是必需的,因为您需要先完成整个文件的读取,然后再写回同一个文件(否则您将得到一个空文件)
2018-11-23 15:03:06;$https://super.cz;$Super.cz
2018-11-26 14:09:06;$https://novinky.cz;$Novinky
2018-11-27 08:06:13;$https://www.google.com;$Google.com
etc.
$file = 'C:\path\to\your.csv'
(Get-Content $file) | Where-Object {
$_ -notlike '*;$'
} | Set-Content $file