Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Can someone explain this shell script?

Options
  • 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