Q:

extract the filename from a path in a Bash

I have a file which has a lot of links and I need bash script to extract all the names of the files which end with .pdf format ?

A:

You can extract the names with
grep -o '[^/]*\.pdf' example

[^/] matches any single character that is not /
[^/]*\.pdf is a (possibly empty) sequence of non-/ characters, followed by the characters .pdf (the backslash before the period makes it literal - otherwise . in a regex matches any character)
the grep -o flag outputs each matching portion, one match per line

To de-duplicate the, pipe through sort and uniq, or sort -u
grep -o '[^/]*\.pdf' example | sort -u

