开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜