我正在使用Powershell和7zip提取.tgz档案。 7zip具有强制详细模式并污染我的屏幕。我只想显示错误消息。我已经使用FIND删除了标准消息:
代码:
Write-Host "Extracting "$strArgument
# extract tgz to tar
& "$7z" x "-y" $strArgument | FIND /V "ing " | FIND /V "Igor Pavlov" | FIND /V "Processing " | FIND /V "Everything is Ok" | FIND /V "Folders: " | FIND /V "Files: " | FIND /V "Size: " | FIND /V "Compressed: " | FIND /V "Processing archive: "
# path to .tar
$strArgument = $strArgument.Replace(".tgz", ".tar")
$strArgument = $strArgument.Replace("i\data\", "")
# extract tar to file
#Write-Host $strArgument
& "$7z" x "-y" $strArgument | FIND /V "ing " | FIND /V "Igor Pavlov" | FIND /V "Processing " | FIND /V "Everything is Ok" | FIND /V "Folders: " | FIND /V "Files: " | FIND /V "Size: " | FIND /V "Compressed: " | FIND /V "Processing archive: "
这给了我一个包含大量空行的输出:
Extracting Q:\mles\etl-i_test\i\data\divider-bin.tgz
Extracting Q:\mles\etl-i_test\i\data\divider-conf.tgz
...
但我只是想:
Extracting Q:\mles\etl-i_test\i\data\divider-bin.tgz
Extracting Q:\mles\etl-i_test\i\data\divider-conf.tgz
如何从流中删除空白行?是否有强大的FIND开关?
答案 0 :(得分:1)
我知道最简单的方法是通过-match运行结果并过滤掉任何不包含非空格的内容:
Write-Host "Extracting "$strArgument
# extract tgz to tar
& "$7z" x "-y" $strArgument | FIND /V "ing " | FIND /V "Igor Pavlov" | FIND /V "Processing " | FIND /V "Everything is Ok" | FIND /V "Folders: " | FIND /V "Files: " | FIND /V "Size: " | FIND /V "Compressed: " | FIND /V "Processing archive: "
# path to .tar
$strArgument = $strArgument.Replace(".tgz", ".tar")
$strArgument = $strArgument.Replace("i\data\", "")
# extract tar to file
#Write-Host $strArgument
(& "$7z" x "-y" $strArgument | FIND /V "ing " | FIND /V "Igor Pavlov" | FIND /V "Processing " | ND /V "Everything is Ok" | FIND /V "Folders: " | FIND /V "Files: " | FIND /V "Size: " | FIND /V "Compressed: " | FIND /V "Processing archive: ") -match '\S'
答案 1 :(得分:1)
find
没有这样的开关,但您可以将findstr
替换为正则表达式:
... | findstr /r /v "^$"