Warm tip: This article is reproduced from stackoverflow.com, please click
bash linux sed awk

Extract string from square brackets and quotes

发布于 2020-03-29 12:48:21

I was trying to extract strings of the following form:

[["abc"]] --> abc

So I wrote echo "[[\"abc\"]]" | sed -e 's/\[\[\"//g' | sed -e 's/\"\]\]//g'

And it works fine but looks extremely ugly. I'm pretty much sure that there should be a neater solution for such a simple case?

Can you please advice some sed or awk enhancement for that?

Questioner
St.Antario
Viewed
94
Lewis M 2018-09-08 03:44

If you are just looking for what is between the double-quotes, try this

echo '[["abc"]]' | awk -F\" '{print $2}'

Hope this helps