Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Can someone explain this shell script?

  • 13-04-2014 12:54AM
    #1
    Closed Accounts Posts: 147 ✭✭


    grep "generate_204" | tr '"' '\n' |
    grep "generate_204" |sed 's|http:\\/\\/|http://|g' |
    sed 's|youtube.com\\/|youtube.com|g' |sed 's|\\u0026|\&|g' |
    sed 's|generate_204|videoplayback|g'

    What exactly is going on there?


Comments

  • Closed Accounts Posts: 4,763 ✭✭✭Fenster


    Ghetto find and replace on a string related to a YouTube video. What I don't see in the that code snippet is the file or URL that was passed to it to be processed. It should start with the input, something like (but not necessarily):
    cat $foo
    

    Starting at this point:
    grep "generate_204" | tr '"' '\n' |
    

    1. Search for line containing string 'generate_204' and use replace the " character with the newline (\n) character.
    grep "generate_204" | sed 's|http:\\/\\/|http://| g' |
    

    2. Search for line containing string 'generate_204' and use sed to un-escape the protocol part of the URL (http).
    sed 's|youtube.com\\/|youtube.com|g' |
    

    3. Search the string modified in part 2 and un-escape 'youtube.com' by changing 'youtube.com\/' to 'youtube.com'.
    sed 's|\\u0026|\&|g' |
    

    4. Search the string modified in part 3 and un-escape the ampersand ('&') character, which has interestingly been encoded in a non-standard manner.
    sed 's|generate_204|videoplayback|g'
    

    5. Finally, replace the Google status message that we've used to search this string with 'videoplayback'.

    Overall, this code looks like it is part of some kind of scraper.


Advertisement