Dear Friends,
I want to take last 10 characters of a file name in a variable.
E.g.
file name is
123432311234567890.txt
then we want "1234567890" to be taken in an variable.
Request you to guide me to do the same
Thanks in anticipation
Anushree
clx
2
try
$ a=123432311234567890.txt
$ expr $a : '.*\(..........\).txt'
1234567890
$
Tytalus
3
one way:
# echo "123432311234567890.txt" | nawk -F. '{print substr($1,length($1)-9,10)}'
1234567890
ctsgnb
4
# a=123432311234567890.txt
# a=${a%.*};t=${a%??????????};echo "${a#$t}"
1234567890
# echo "123432311234567890.txt" | sed 's/.*\(.\{10\}\)\.txt/\1/'
1234567890
# a=123432311234567890.txt
# typeset -R10 a=${a%.*}
# echo $a
1234567890
kurumi
5
var=$(echo "123432311234567890.txt" | ruby -e 'puts gets.split(/\./)[0..-2].join(".")[-10..-1]')
through sed..
STR=$(echo "123432311234567890.txt"|sed 's/.*\(.\{10\}\).txt/\1/')
Ygor
7
Or...
STR=$(basename 123432311234567890.txt .txt | tail -c 11)
rdcwayx
8
echo 123432311234567890.txt |awk '{print substr($0,length-13,10)}'