giliermo
giliermo

Reputation: 161

How can i take variable from a text file using grep and sed?

i have text file :

"NAME": "Linda",
    "AGE": "34",
"NAME": "Arnold",
    "AGE": "99",

and i want to get arnol's age : 99

i try this --> cat file.txt | grep "AGE" | sed -n 2p

output : "AGE": "99",

how can i output only 99?

thanks

Upvotes: 0

Views: 72

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627100

You may replace your sed command with

sed -n '2 s/.*"\(.*\)".*/\1/p'

It will extract just the value in the last pair of quotes.

See an online demo.

Upvotes: 1

Related Questions