0

我正在使用 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 开关吗?

4

2 回答 2

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'
于 2013-03-28T10:55:37.830 回答
1

find没有这样的开关,但您可以使用findstr正则表达式:

... | findstr /r /v "^$"
于 2013-03-28T12:04:52.917 回答