Question: Assuming the following file structure:

```
[topic1]
key1 = "value1"
key2 = "value2"
[topic2]
key1 = "value3"
.
.
.

```

How can I extract value2 from key2 from topic1 to the shell?I'm used to use jq to read json file and get key-value entries but I have no idea to extract the key value in this situation.

Answer: 
```
$ awk -F' *= *"|"$' '
    gsub(/^\[|]$/,"") { topic=$0; next }
    (topic=="topic1") && ($1=="key2") { print $2 }
' file
value2

```
> 
> topics are not ordered, so how to define only one?
> 
> 
> 

Just specify `/^\[/` (the beginning of a following topic) as the second pattern (end) of the address range, e. g.:

```
sed -n '/^\[topic1]/,/^\[/s/key2 = "\(.*\)"/\1/p' file

```