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_Replace_Command Line - Fatal编程技术网

希望使用powershell从文本文件中删除文本

希望使用powershell从文本文件中删除文本,powershell,replace,command-line,Powershell,Replace,Command Line,我正在尝试编辑一个包含各种html元素的大型纯文本文档,例如: & & & & 在更极端的情况下& 我的目标是从文本文件中删除任何。我没有与powershell合作过很多,所以我的知识有限,尽管如此,我还是尝试了一下 用于更换所有 获取内容“C:\Users\John\Desktop\input.txt”|-替换“\”,“”|输出文件C:\Users\John\Desktop\output.txt 上述脚本出现以下错误: -替换:术语'-replace'不能识别为cmdlet、函数、脚本文

我正在尝试编辑一个包含各种html元素的大型纯文本文档,例如:

  • &

  • &
  • &
  • &
  • 在更极端的情况下<代码>&
我的目标是从文本文件中删除任何
。我没有与powershell合作过很多,所以我的知识有限,尽管如此,我还是尝试了一下

用于更换所有

获取内容“C:\Users\John\Desktop\input.txt”|-替换“\”,“”|输出文件C:\Users\John\Desktop\output.txt
上述脚本出现以下错误:

-替换:术语'-replace'不能识别为cmdlet、函数、脚本文件或可操作程序的名称


当您使用
-replace
时,必须确保正确地将字符串解析为调用。 有两种方法可以解决您的问题:

1。使用foreach遍历文件的每一行,并在每一行上使用
-replace
(如果您想对这些行执行其他操作,这可能会很有帮助):


试试
。|%{$\替换“\”、“}”\…
(获取内容文件)-替换“\”
您是从其他纯文本文件中删除HTML标记,还是从实际HTML文件中删除标记?对于后者,我建议使用适当的HTML解析器。@AnsgarWiechers它是一个纯文本文件。对不起,我应该在帖子里说出来。@Paxz,这很有魅力。如果你写了一篇包含这个回复的帖子,我会把它标记为已解决。
get-content "C:\Users\John\Desktop\input.txt" | -replace "\<.*?\>","" | Out-File C:\Users\John\Desktop\output.txt
get-content "C:\Users\John\Desktop\input.txt" | % {$_ -replace "\<.*?\>",""} | Out-File C:\Users\John\Desktop\output.txt
(get-content "C:\Users\John\Desktop\input.txt") -replace "\<.*?\>","" |  Out-File C:\Users\John\Desktop\output.txt