1

Hi every one i am trying to read a string which is enclosed in double quotes within a file e.g "cars" : I am using this command but unable to read it may be I am not using the right format to read the quotes

$houseid = $json |Get-Content |Select-String -pattern ""houseid":"| measure | select -exp count write-host "houseid = " $houseid 

I am reading the file from json file

1 Answer 1

2

Wrap you pattern in single quotes when it contains quotes. Although it's not necessary, you should add -SimpleMatch to specify that it is a normal string-pattern and not regex.

#Valid sample '"houseid":myjsonvalue' | Select-String -Pattern '"houseid":' -SimpleMatch | measure | select -ExpandProperty count 1 #Invalid sample 'houseid:myjsonvalue' | Select-String -Pattern '"houseid":' -SimpleMatch | measure | select -ExpandProperty count 0 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.