We have the following unix command:
/usr/bin/tail -n 1 %{path} | grep --silent -F \"%{message}\" && rm -f %{path}%
This:
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'"
You can use tailhead.bat (pure batch script utility) that can be used to show lasts/fists lines of a file.Instead of Grep
you can use findstr
or find
:
tailhead.bat tailhead -file=%pathToFile% -begin=-3|find "%message%"