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="[^"]*"'
精彩评论