Unix的尾巴和grep等同于Windows [英] Unix tail and grep equivalent for Windows

查看:109
本文介绍了Unix的尾巴和grep等同于Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下的unix命令:

We have the following unix command:

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


  1. 的/ usr / bin中/尾-n 1%{路径} 获取文件的最后一行的路径变量引用

  1. /usr/bin/tail -n 1 %{path} gets the last line in the file that the path variable refers to

| grep的--silent -F%{}消息管道输出到另一个命令,的grep ,检查如果$ p的输出$ pvious命令等于的消息

| grep --silent -F "%{message}" pipes the output to another command, grep, which checks if the output of the previous command is equal to the value of message

以上线是在配置文件中是允许将呼叫到底层操作系统的。

The above line is in a configuration file which is allows for calls to be made to the underlying operating system.

我要复制Windows上的functionalirty。
我想这样的:

I want to replicate the functionalirty on windows. I tried this:

command => 'powershell -Command "& {Get-Item $args[0] | ? { (Get-Content $_ -Tail 1).Contains($args[1]) }| Remove-Item -Force}" "'%path%'" "'%message%'"'

这引发错误:

Error: Expected one of #, {, } at line 15, column 131 (byte 498)

线15是包含上述配置文件中的行。

Line 15 is the line in the configuration file which contains the above.

感谢

推荐答案

PowerShell的解决方案:

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'"

这篇关于Unix的尾巴和grep等同于Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆