Unix tail and grep equivalent for Windows

前端 未结 2 1179
青春惊慌失措
青春惊慌失措 2021-01-26 22:16

We have the following unix command:

/usr/bin/tail -n 1 %{path} | grep --silent -F \"%{message}\" && rm -f %{path}%

This:

2条回答
  •  暖寄归人
    2021-01-26 23:00

    PowerShell solution:

    $path    = 'C:\path\to\your.txt'
    $message = 'message'
    
    Get-Item $path | ? { (Get-Content $_ -Tail 1).Contains($message) } | Remove-Item -Force
    

    If you want to run it from a command line, call it like this:

    powershell -Command "& {Get-Item $args[0] | ? { (Get-Content $_ -Tail 1).Contains($args[1]) } | Remove-Item -Force}" "'C:\path\to\your.txt'" "'message'"
    

提交回复
热议问题