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
Post a Comment