Reputation: 3476
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?
Upvotes: 0
Views: 383
Reputation: 200303
find
does not have a switch like that, but you can use findstr
with a regular expression instead:
... | findstr /r /v "^$"
Upvotes: 1
Reputation: 68283
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'
Upvotes: 1