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

Caused by: java.sql.SQLTimeoutException: ORA-01013: user requested cancel of current operation

HashiCorp Vault Integration with Ansible Etower using approle

utility to extract date from text with java