get filenames from log

Hi.

I'm trying to get the names of files from a log file, without the path and special characters.
I have a file that contains lines like this:

'/path/to/files/file00010000070874.EXT'
'/path/to/files/file00010000070875.EXT'
'/path/to/files/file00010000070876.EXT'
'/path/to/files/file00010000070877.EXT'
'/path/to/files/file00010000070878.EXT'
'/path/to/files/file00010000070879.EXT'
'/path/to/files/file00010000070880.EXT'
'/path/to/files/file00010000070881.EXT'
'/path/to/files/file00010000070882.EXT'
'/path/to/files/file00010000070883.EXT'

I would like to create a file from this that contains only the file names like this:

file00010000070874.EXT
file00010000070875.EXT
file00010000070876.EXT
file00010000070877.EXT
file00010000070878.EXT
file00010000070879.EXT
file00010000070880.EXT
file00010000070881.EXT
file00010000070882.EXT
file00010000070883.EXT

The path is usually the same but the file name may vary only the extension and the beginning of the name is the same.

For the moment I'm using cut but that is not an elegant solution and if the file names aren't the same I would always have to adjust the script.

Thanks in advance.

awk -F\' '{sub(/.*\//,"",$2);print $2}' logfile
1 Like
awk -F "['/]" '{ print $(NF-1)}' file
1 Like

That was fast :slight_smile:
Thank you both worked.

sed 's:\(.*\)/\(.*\).:\2:' infile