tonio94
tonio94

Reputation: 510

Extract value between quotes after colon

I would like to extract the value of a parameter, it is separated by a colon and both -parameter and value- are between double quotes.

I tried to do it with awk, but using colon as a separator doesn't work because of the colons you see in the value.

"param1" : "u:user1:A,u:user2:B,u:user3:A,g:group1:A,g:group2:C",

I just want to extract this : u:user1:A,u:user2:B,u:user3:A,g:group1:A,g:group2:C, in order to append a new value at the end with my script.

Thanks

Upvotes: 0

Views: 244

Answers (2)

RavinderSingh13
RavinderSingh13

Reputation: 133538

try following with awk and let me know if this helps you.

awk -F'"' '{print $4}'   Input_file

Upvotes: 1

glenn jackman
glenn jackman

Reputation: 246847

Using a double quote as the delimiter, you take the 4th field:

$ str='"param1" : "u:user1:A,u:user2:B,u:user3:A,g:group1:A,g:group2:C",'
$ value=$( cut -d'"' -f4 <<<"$str" )
$ echo "$value"
u:user1:A,u:user2:B,u:user3:A,g:group1:A,g:group2:C

Upvotes: 1

Related Questions