I have an http link : http://www.test.com/abc/def/efg/file.jar and I want to save the last part file.jar to variable, so the output string is file.jar.Condition: link can has different length e.g.:http://www.test.com/abc/def/file.jar.I tried it that way: awk -F'/' '{print $7}', but problem is the length of URL, so I need a command which can be used for any URL length.
How to get last part of http link in Bash?
bash;shell script;awk;cut
Using awk for this would work, but it's kind of deer hunting with a howitzer.  If you already have your URL bare, it's pretty simple to do what you want if you put it into a shell variable and use bash's built-in parameter substitution:$ myurl='http://www.example.com/long/path/to/example/file.ext'$ echo ${myurl##*/}file.extThe way this works is by removing a prefix that greedily matches '*/', which is what the ## operator does:${haystack##needle} # removes any matching 'needle' from the                    # beginning of the variable 'haystack'