Home > OS >  windows powershell findstr incorrect behaviour
windows powershell findstr incorrect behaviour

Time:09-14

I am looking for a search string inside a json file:

> type .\input.json
[
    {"name": "moish"},
    {"name": "oren"}
]
> type .\input.json | findstr /n /l "\`"name\`": \`"or"
2:    {"name": "moish"},
3:    {"name": "oren"}

How come moish entry is found? what am I missing?

CodePudding user response:

Escape the literal quotation marks by doubling them:

type input.json |findstr /n /l """name"": ""or"

... or use single-quotes to qualify the search term:

type input.json |findstr /n /l '"name": "or'

.... or perhaps use the native PowerShell cmdlet Select-String instead of findstr:

Select-String -LiteralPath input.json -Pattern '"name": "or'
  • Related