way 1:
$ ls -lrt | awk '{ f=$NF }; END{ print f }'
#
#The above awk is to print the last argument of the last line
#
way 2:
$ ls -t1 | head -n
REFERENCE: bash - parameter expansion, i.e. http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
file=data.txt echo ${file%.*} echo ${file#*.}
outputs the file base and extension respectively ("data" and "txt").
${variable#pattern} is similar to "echo $variable |sed 's/^pattern//'"
but the pattern matching isn't "greedy" unless you double the #.
Likewise ${variable%pattern} is similar to
"echo $variable | sed 's/pattern$//'"
No comments:
Post a Comment