Unix/Linux Inline command for extracting file and filetype

 filetype=`echo $f | awk '{n=split($0, a, ".")} END{print a[n] }'`  

 filename=`echo $f | awk '{n=split($0, a, "/")} END{print a[n] }'`  

where $f is the full path of the file. It can be used directly too as..

 filetype=`echo "/home/myuser/a.b.c.d.txt" | awk '{n=split($0, a, ".")} END{print a[n] }'`  

output : txt

 filename=`echo "/home/myuser/a.b.c.d.txt" | awk '{n=split($0, a, "/")} END{print a[n] }'`  

output: a.b.c.d

Comments

Popular posts from this blog

Delete horizontal, vertical and angled lines from an image using Python to clear noise and read text with minimum errors

Unordered JSON compare for differences using javascript

Java Currency Formatter Changing $ to ¤