windows - 在其他PC上运行相同的power-shell命令时出错

标签 windows powershell compiler-errors

我正在运行以下命令。$ tail -n +2000 text.txt > text.txt.new && mv text.txt.new text.txt这在使用PowerShell版本Version 5.1.18362.145的HP笔记本电脑上有效
然后,我移到工作站,在其中运行相同的代码,相同的PowerShell版本,但收到此错误

At line:1 char:41

'+' $ tail -n +2000 text.txt > text.txt.new && mv text.txt.new text.txt

'+' ~~

The token '&&' is not a valid statement separator in this version.

'+' CategoryInfo : ParserError: (:) [],


ParentContainsErrorRecordException

'+' FullyQualifiedErrorId : InvalidEndOfLine



我尝试了另一台PC并遇到相同的错误,我也查看了这些版本,似乎无法找出为什么它可以在我的笔记本电脑上工作。
使用此代码$ tail -n +2000 text.txt > text.txt.new && mv text.txt.new text.txt我正在尝试从文本文件的开头删除2000行
我使用了代码Get-Host | Select-Object Version来找出版本。
如果还有另一种方法来删除这2000行,请让我知道,或者如果您对同一命令在工作站上不起作用的原因有解决办法,请告诉我。 (必须是单行命令)
笔记本电脑是Windows 10家庭版1903版
工作站是Windows 10 Pro 1903版

最佳答案

您可以通过Select-Object开关使用-Skip

Get-content c:\temp\input.txt | Select-Object -Skip 2000 | Set-Content c:\temp\output.txt

关于windows - 在其他PC上运行相同的power-shell命令时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58642374/

相关文章:

java - 如何在linux机器中导入jar文件

c++ - 后面加void违法吗?

c - 错误 : initializer element is not a compile-time constant

windows - 为什么 Docker 服务停止?

c# - 默认情况下,如何将新的 Windows 用户添加到用户组

powershell - 使用 UniqueKeyContainerName 获取证书绝对路径

powershell - 如何替换字符串/文件末尾的字符?

windows - 将文件保存在 vim 中的不同文件夹中

node.js - 如何在 Windows 10 上修复错误 : spawn UNKNOWN with node. js v7.8.0?

powershell - PowerShell -and 条件运算符