Bash - extract the file name and extension of a string

advertisements

Here is grep command:

grep "%SWFPATH%/plugins/" filename

And its output:

set(hotspot[hs_bg_%2].url,%SWFPATH%/plugins/textfield.swf);
set(hotspot[hs_%2].url,%SWFPATH%/plugins/textfield.swf);
url="%SWFPATH%/plugins/textfield.swf"
url="%SWFPATH%/plugins/scrollarea.swf"
alturl="%SWFPATH%/plugins/scrollarea.js"
url="%SWFPATH%/plugins/textfield.swf"

I'd like to generate a file containing the names of the all files in the 'plugins/' directory, that are mentioned in a certain file.

Basically I need to extract the file name and the extension from every line. I can manage to delete any duplicates but I can't figure out how to extract the information that I need.

This would be the content of the file that I would like to get:

textfield.swf
scrollarea.swf
strollarea.js

Thanks!!!

PS: The thread "Extract filename and extension in bash (14 answers)" explains how to get filename and extension from a 'variable'. What I'm trying to achieve is extracting these from a 'file', which is completely different'


For this specific problem

awk '/\/plugins\// {sub(/.*\//, ""); sub(/(\);|")?$/, "");
   arr[$0] = $0} END {for (i in arr) print arr[i]}' filename