0

I'm extracting .tgz archives with Powershell and 7zip. 7zip has a forced verbose mode and pollutes my screen. I just want to display the error messages. I already removed the standard messages with FIND:

Code:

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

This gives me an output with lots of empty lines:

Extracting  Q:\mles\etl-i_test\i\data\divider-bin.tgz










Extracting  Q:\mles\etl-i_test\i\data\divider-conf.tgz
...

However I just want:

Extracting  Q:\mles\etl-i_test\i\data\divider-bin.tgz
Extracting  Q:\mles\etl-i_test\i\data\divider-conf.tgz

How can i remove the blank lines from my stream? Is there a mighty FIND switch?

mles
  • 4,534
  • 10
  • 54
  • 94

2 Answers2

1

Easiest way I know is to run the result through -match and filter out anything that doesn't contain non-whitespace:

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'
mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • is it possible to put all of the FINDs in a single regex for -match too? – mles Mar 28 '13 at 13:10
  • Yes, and no. You can put them all in a single regex using alternation, but the way you're doing it you'd want to use -notmatch against that regex. It would probably be much easier to write the regex to match the lines you want to keep. eg -match '^Extracting'. I'd have offered exactly that as a better solution but the bit about only wanting to keep errors made me think there might be more to it that would need to be included. – mjolinor Mar 28 '13 at 13:17
1

find does not have a switch like that, but you can use findstr with a regular expression instead:

... | findstr /r /v "^$"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328