Search code examples
imagecygwintumblr

Compare two links and choose the one with higher end number


So my problem is I try to compare two links from tumblr and choose that link which has higher number in this case is just choose _1280 over _500.

http://25.media.tumblr.com/393e9f295c4cac3af0a4b6d3a64c434d/tumblr_mi9e85iFwA1qavye5o1_500.jpg http://25.media.tumblr.com/393e9f295c4cac3af0a4b6d3a64c434d/tumblr_mi9e85iFwA1qavye5o1_1280.jpg

I know how to get image links from tumblr but I'm too stupid to make, a code for this. I don't even know how to start... And this is just my beginning of trying do something in bash (cygwin).

I will appreciate any help :)


Solution

  • Here are some string manipulation functions to get you started.

    bash:~$ var1=http://25.media.tumblr.com/393e9f295c4cac3af0a4b6d3a64c434d/tumblr_mi9e85iFwA1qavye5o1_500.jpg
    bash:~$ var2=${var1##*_}
    

    This gives you the part of the string after the last underscore

    bash:~$ echo $var2
    
    should output 500.jpg
    
    bash:~$ var3=${var2%.*}
    

    This gives you the part before the dot

    bash:~$ echo $var3
    
    should output 500
    

    Then you can compare the numbers.