Kac*_*che 5 windows command-line batch-file
这个问题是继续关于有选择地将行从一个文件附加到另一个文件的另一个问题.
我正在使用的正则表达式在匹配行保持/丢弃时效果很好.问题是该文件是由一堆其他文件组成的,有时我想要保留的行作为UTF-8编码文件的第一行开始.这意味着该findstr命令返回如下内容:
???LineToKeep that started out as the first line in its file
LineToKeep another
LineToKeep more lines
???LineToKeep that started out as the first line in its file
LineToKeep more
Run Code Online (Sandbox Code Playgroud)
保证除了BOM字节外,该行始终以"LineToKeep"开头.如何摆脱这三个UTF-8 BOM字节,因为这些windows shell命令无法正确处理它们?
我希望有一种方法可以将它们移除到位,或者可能是对findstr上一个问题的命令的修改.
因为我知道每一行必须以"LineToKeep"或"∩╗┐LineToKeep"开头,所以我认为有一种方法可以计算出if (Line[3:10] == "LineToKeep") { Line = Line[3:]; }每行的内容.
我最终在 Windows cmd 中调用 PowerShell:
powershell . "Get-ChildItem . | Select-String '^LineToKeep' | foreach {$_.Line}"
Run Code Online (Sandbox Code Playgroud)