I have a text file that conatins some HTML information like this:
<li><a href="https://www.youtube.com/watch?v=YDubYJsZ9iM&list=PL5-da3qGB5IBC-MneTc9oBZz0C6kNJ-f2">Lab: K-means Clustering</a> (6:31)</li>
<li><a href="https://www.youtube.com/watch?v=4u3zvtfqb7w&list=PL5-da3qGB5IBC-MneTc9oBZz0C6kNJ-f2">Lab: Hierarchical Clustering</a> (6:33)</li>
<li><a href="https://www.youtube.com/watch?v=jk9S3RTAl38&list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interview with John Chambers</a> (10:20)</li>
<li><a href="https://www.youtube.com/watch?v=6l9V1sINzhE&list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interview with Bradley Efron</a> (12:08)</li>
<li><a href="https://www.youtube.com/watch?v=79tR7BvYE6w&list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interview with Jerome Friedman</a> (10:29)</li>
<li><a href="https://www.youtube.com/watch?v=MEMGOlJxxz0&list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interviews with statistics graduate students</a> (7:44)</li>
I extract links with grep -oP "https:\/\/www.youtube.com\/watch\?v=([A-Za-z0-9-_]+)" list > links
such that list
is html file. From another side i need extract the name of each file, i.e. i need another list like this:
Lab: K-means Clustering
Lab: Hierarchical Clustering
Interview with John Chambers
Interview with Bradley Efron
Interview with Jerome Friedman
Interviews with statistics graduate students
The problem is that i have some tags like <a href="http://www-bcf.usc.edu/~gareth/ISL/">An Introduction to Statistical Learning with Applications in R</a>
, thus i can't use some pattern with a
tag. So i must use somethings like pattern grouping that i will able to use some $1
for first matched pattern, $2
for second pattern and so on into https:\/\/www.youtube.com\/watch\?v=([A-Za-z0-9-_]+)/[SOME INFORMATION ON URL HERE]/([A-Za-z0-9-_]+)
. How can i do this on terminal (Bash)?