[英]How to remove the first 3 symbols in a text file?
如何使用PowerShell删除文本文件中的前3个符号并保持文件名称相同?
Just read the file using the Get-Content
cmdlet, remove the file using a regex that replaces the first three characters with nothing and finally write it back using the Set-Content
cmdlet: 只需使用
Get-Content
cmdlet读取文件,使用正则表达式将文件中的前三个字符替换为Set-Content
,然后使用Set-Content
cmdlet将其写回即可:
(Get-Content 'yourfilePath.txt' -raw) -replace '^...' | Set-Content 'yourfilePath.txt'
Note: You probably want to specify the encoding using the -Encoding
parameter when writing the content back to the file. 注意:在将内容写回到文件时,您可能希望使用
-Encoding
参数指定编码 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.