Skip to main content
added 8 characters in body
Source Link
Shane Bishop
  • 243
  • 1
  • 3
  • 14

I want to use select-string on the output of another command (similar to how one would use grep on a Unix OS).

Here is the output of the command without the select-string:

> (dir resources).Name
wmd-Linux-22022.json
wmd-Linux-22023.json
wmd-Linux-22024.json
wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json
> (dir resources).Name
wmd-Linux-22022.json
wmd-Linux-22023.json
wmd-Linux-22024.json
wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json

When I use select-string, I get blank lines for some reason:

> (dir resources).Name | select-string Windows

wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json


> (dir resources).Name | select-string Windows

wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json


How can I either (A) tell select-string to eat the blank lines with no matches, or (B) pipe the output to another powershell utility that could eat the blank lines for me?

I want to use select-string on the output of another command (similar to how one would use grep on a Unix OS).

Here is the output of the command without the select-string:

> (dir resources).Name
wmd-Linux-22022.json
wmd-Linux-22023.json
wmd-Linux-22024.json
wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json

When I use select-string, I get blank lines for some reason:

> (dir resources).Name | select-string Windows

wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json


How can I either (A) tell select-string to eat the blank lines with no matches, or (B) pipe the output to another powershell utility that could eat the blank lines for me?

I want to use select-string on the output of another command (similar to how one would use grep on a Unix OS).

Here is the output of the command without the select-string:

> (dir resources).Name
wmd-Linux-22022.json
wmd-Linux-22023.json
wmd-Linux-22024.json
wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json

When I use select-string, I get blank lines for some reason:

> (dir resources).Name | select-string Windows

wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json


How can I either (A) tell select-string to eat the blank lines with no matches, or (B) pipe the output to another powershell utility that could eat the blank lines for me?

Source Link
Shane Bishop
  • 243
  • 1
  • 3
  • 14

How to use select-string without blank lines?

I want to use select-string on the output of another command (similar to how one would use grep on a Unix OS).

Here is the output of the command without the select-string:

> (dir resources).Name
wmd-Linux-22022.json
wmd-Linux-22023.json
wmd-Linux-22024.json
wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json

When I use select-string, I get blank lines for some reason:

> (dir resources).Name | select-string Windows

wmd-Windows-22022.json
wmd-Windows-22023.json
wmd-Windows-22024.json


How can I either (A) tell select-string to eat the blank lines with no matches, or (B) pipe the output to another powershell utility that could eat the blank lines for me?