I have a shell script which reads a file named filelist.txt, containing a list of fully qualified filenames (with complete path), and then does some processing based on the file extension. In order to do the processing, I have to know the file extension, the filename without extension and just the filename_with_extension(excluding the full path)
some sample lines in the filelist.txt looks like this
/home/johndoe/test/a.java
/home/rwilliams/test2/b.xml
My script looks like below (basically I am using awk and relying on "." to give me the extension and filename_without_extension
The problem is this script works fine for normal files with names like /home/johndoe/test/a.java
however whenever I encounter files with names like /home/john.doe/test/abcd.efgh.ijkl.mnop.qrst.xml
the script throws up as it relies heavily on the "." character embedded in the name to be the separator between the extension and filename.
The solution proposed above returns file extension and filename excluding the full path and the extension, ONLY if the format of the filename is something like /home/john.doe/test.java or /home/john.doe/test.test1.test2.test3.java;
However unfortunately whenever it encounters a filename without an extension e.g. /home/john.doe/runjava then the script returns runjava as the file extension instead of returning null as file extension and the filename excluding the full path and the extension is returned as null instead. (kinda it's doing a complete switcheroo)
Is there a way to handle this? because I just realized that there are quite a few executables I have in my filelist.txt without any extensions as such (like /bin/gzip, /usr/local/bin/perl etc.) and my script just craps out when it encounters them. Any help will be really appreciated!