question about grep
hello guys, im a starting out with linux and there is something i been stuck on
I been trying to display just the number of views from the youtube source code. my professor gave us this command line to do it but for some reason i cant get it to work Code:
grep data-item sourcecode.html | while read x : do views= expr "$x":".*data-content-item-views=\"\(.*\) views.*" Code:
<div class="feed-item-content-wrapper clearfix context-data-item" data-context-item-time="24:39" data-context-item-actionuser="FUNimation" data-context-item-user="FUNimation" data-context-item-views="232,184 views" data-context-item-id="ff7N_X2Omkc" data-context-item-title="Fairy Tail - 18 - Reach the Sky Above (SUB)" data-context-item-type="video"> |
Here’s a suggestion:
Code:
youtube-viewer -i 'http://www.youtube.com/watch?v=B89N78zeKAs' | grep Views | awk '{print $4}' |
Try:
Code:
~$ awk '/data-context-item-views/ {print $8}' inputfile.html | awk -F"=" '{gsub(/\"/,"",$0); print $2}' |
Sorry
Thx for Ur help, but I forgot to mention that I can only use the Grep command , that's what the professors told us
|
Quote:
For more understanding, check manaul of grep here. So using grep you can search the line having string views only. |
Quote:
Code:
bash-4.2$ grep -A 1 "watch-view-count" watch.htm | grep -Eo '[0-9]*$' "watch-view-count" = in the line before the count watch.htm = is the html file from the youtube page you can also feed it with Code:
bash-4.2$ cat watch.htm | grep -A 1 "watch-view-count" | grep -Eo '[0-9]*$' o = print only matching part of expression because before the number are spaces this is a way to get rid of them. '[0-9]*$' = the regular expression [0-9] means character between 0 and 9 and the * means repeat the expression before * zero or more times, in this case look for each other following characters between 0 and 9. And the $ means the characters must be at the end of the line. |
I must learn to first read the question
Code:
bash-4.2$ echo '<div class="feed-item-content-wrapper clearfix context-data-item" data-context-item-time="24:39" data-context-item-actionuser="FUNimation" data-context-item-user="FUNimation" data-context-item-views="232,184 views" data-context-item-id="ff7N_X2Omkc" data-context-item-title="Fairy Tail - 18 - Reach the Sky Above (SUB)" data-context-item-type="video">'| grep -Eo "[0-9,]* views" | grep -Eo "[0-9,]*" -Eo "[0-9,]*" = extract the number result is 232,184. |
All times are GMT -5. The time now is 01:11 PM. |