Score:0

How to extract channel names from YouTube subscription source file

jp flag

I have an html source file of YouTube subscriptions, and want to extract just the /user/CHANNELNAME parts into a separate file.

The source file (browser > youtube.com > subscriptions > manage > Ctrl+U) has that information wrapped up into sections like this:

"url":"/user/CHANNELNAME","webPageType":"WEB_PAGE_TYPE_CHANNEL","rootVe":3611,"apiUrl":"/youtubei/v1/browse"

I'm trying to use grep -o to extract the /user/CHANNELNAME part, but my attempts always fall foul of the greedy *.

$ grep -o '/user/.*"' source

Results in grep matching:

/user/CHANNELNAME","webPageType":"WEB_PAGE_TYPE_CHANNEL","rootVe":3611,"apiUrl":"/youtubei/v1/browse"

Or:

$ grep -o '/user/.*,' source

Results in grep matching the same:

/user/CHANNELNAME","webPageType":"WEB_PAGE_TYPE_CHANNEL","rootVe":3611,"apiUrl":"/youtubei/v1/browse"

How do I get grep to stop at the first " or ,

pl flag
`grep -o '/user/.*,' source | awk -F '"' '{print $1}'`
Broadsworde avatar
jp flag
That doesn't work, I just get pages of commas and nothing else!
Broadsworde avatar
jp flag
Source file via Ctrl+U (so HTML) on Manage Subscriptions YouTube page (updated question for clarity)
Score:1
US flag
user1676974

The text you want seems to be inside double quotes, if this is always the case, instead of matching any character (.) try matching any character but double quotes:

grep -o '/user/[^"]*' source

The ^ inverts the match. Assuming there is always a comma, you could use [^",] if some of the channel names aren't surrounded by double quotes

In case you are simply looking for the part after /user/, you can use the -P switch of grep to strip the /user/ part while still matching it:

grep -oP '(?<=/user/)[^",]*' source
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.