Print matching field using awk

Hi All,

I have a string like below:

str="Hold=True Map=False 'This will map the data' Run=Yes Modify=False"

I want to print the field Run=Yes and retrive the value "Yes". I cannot use simple awk command because the position of the "Run" will be different at different times. Is there a way to print the matching pattern? There will be only one occurance of the string "Run="

Thanks,
D

Try:

 
$ echo 'str="Hold=True Map=False 'This will map the data' Run=Yes Modify=False"' | sed 's/.*Run=\(.*\) .*/\1/'

Thanks for that.

This is working for the value Run. But if I change the value to be printed from "Run" to "Map" ths output is not correct.

Please could you let me know the usage of sed here

sed 's/.*Run=\(.\) ./\1/'

I believe this looks for the pattern starting after Run= and then does soem operation

Replace the sed with below modified one

sed "s/.*$val=\([^ \'\" ]*\).*/\1/"

make sure that "val" always contains the value your searching for

Many thanks for this. It works !

I am not very good at using the complex expressions in sed .. It will be kind of you if you could put in a line or two what the sed command is doing here...

sed "s/.*$val=\([^ \'\" ]*\).*/\1/"

/.$val=\([^ \'\" ]*\)./ -> search for the value contained in "val" followed by non space and non single quote and non double quote characters .( using grouping \(.*\) ) , print the same using \1.

You can go through :

Sed - An Introduction and Tutorial

Many thanks for that !