Set specific part in command output into variable

I am trying unsuccessfully to set into a variable a specific part of command output:
The command output will be as:
line 1: <varied>
line 2: 2 options:
option 1:
Set view: ** NONE **
or
option 2:
Set view: <different_name_of_views_always_without_spaces>

and I would like to get into the variable either the ** NONE ** or the name of the view (<different_name_of_views_always_without_spaces> in option 2).

What is the syntax to find that "field" into my variable?

Thanks a lot

Something like:

VAR=`herecomesyourcmd| grep 'Set view: ** NONE **'`

If you want the other pattern, you'll have to exchange it.

Thanks,
I tried the advised code as following:
echo "test123"
v1=`ct pwv | grep 'Set view: ** NONE **'`
echo $v1

and I get:
test123

(empty line after the test123)

  1. Any idea?
  2. In the 2nd option for the command output (Set view: <different_name_of_views_always_without_spaces>) the last part (<different_name_of_views_always_without_spaces>) is varied and may be any string, how can I catch that string?

Thanks a lot

For getting nothing as output I guess the grep'ed pattern is wrong then. Best try it without assigning it to a variable if grep finds something on the command line.
For the other pattern you want to find.. can we sum it up that you simply want any output that starts with "Set view:" ?

You need to backslash the asterisks or use fgrep -- asterisk means "the previous character zero or more times" (and doesn't match itself) in regex.

OK, With fgrep it worked.

regarding the other pattern - What I want to be set into the variable is the next string without spaces (till next space or new line) right after "Set view: "
any suggestion?

Thanks a lot!

v1=`ct pwv | sed -n 's/Set view: //p'`

As far as I can tell, the ** NONE ** and the regular case can be handled equivalently; by stripping off the "Set view: " prefix.

perfect!!

Thanks a lot!