String compare using awk - what am I doing wrong?

Hi all,
I was doing some string manipulation in my script and wanted to try using awk. However, I have been stuck with string compare. A simplified form of my conundrum is given below:

The below prints expected result (prints "Completed because that is the second element"):

$ echo '"status":"Completed"' | awk 'BEGIN{FS=":"} /"status"/ {print $2}'
"Completed" 

The below does not print the expected value:

$ echo '"status":"Completed"' | awk 'BEGIN{FS=":"} /"status"/ {print ($2 == "Completed") ? "Yes" : "No"}'
No 

Shouldn't the output above be "Yes" given $2 is "Completed"? What am I doing wrong?

Btw, what I really need to do is set a variable if the string compare is successful. The print-test was just to see if it's work at all, and looks like I need to rethink.

Any help is highly appreciated.

I am a newbie to this forum and apologize if I'm creating an unnecessary thread (as opposed to logging this in an existing thread). If there is one that answers my question, please do suggest.

Hi you should be testing for "\"Completed\""

1 Like

Or ($2 ~ /Completed/) ?

1 Like

Scrutinizer and RudyC's approach

$ echo '"status":"Completed"' | awk -F'[:]' '{print ($2 ~ /Completed/)? "Yes": "No"}'
Yes
$ echo '"status":"Completed"' | awk -F'[:]' '{print ($2 == "\"Completed\"")? "Yes": "No"}'
Yes
1 Like

You could use grep -q :

echo '"status":"Completed"' | if grep -q '"status":"Completed"'
then
    echo Yes
else
    echo No
fi

Thank you all for the timely and useful help. Highly appreciated.

Scrutinizer, RudiC,
Your suggestions were both apt. Thanks.

Akshay,
I will need to read on your usage of

-F'[:]'

I am just beginning to scratch the surface of awk and there are a ton of things I do not yet know. Thanks for the new (for me) usage.
Btw, could you please elaborate a bit on what that expression does? Can I also use something similar for rows (i.e. RS)?

Chbler,
The reason I landed on awk is that I need to read a Json file, and it is essential I break it down into records and fields so I could process it in a structured manner. Thanks for your time nonetheless.