开发者

How do I find everything between two characters after a word using grep, without outputting the entire line?

开发者 https://www.devze.com 2023-02-01 08:11 出处:网络
I am downlading the info.0.json file from xkcd and trying to parse just the alt text.I don\'t care if there are quotes around it or not.The problem it that the info.0.json file is all one line, and th

I am downlading the info.0.json file from xkcd and trying to parse just the alt text. I don't care if there are quotes around it or not. The problem it that the info.0.json file is all one line, and the alt text is in quotes after the word "alt=". Trying cat info.0.json | grep alt just returns the whole file (because it's all one line). What is the 开发者_Go百科grep or sed code that will get me the alt text?


Use the -o switch:

-o, --only-matching show only the part of a line matching PATTERN

Example:

grep -o 'alt="[^"]*"'
0

精彩评论

暂无评论...
验证码 换一张
取 消