Hi Guys!!!!!!!!!!!
How do we extract last 13 characters from a line
I/p:
.R1/new/sv902a.01.per
O/p:
sv902a.01.per
And the no of characters differs in each line..
Kindly help me out in this!!!!!!!!!!!
Thanks in Advance
Hi Guys!!!!!!!!!!!
How do we extract last 13 characters from a line
I/p:
.R1/new/sv902a.01.per
O/p:
sv902a.01.per
And the no of characters differs in each line..
Kindly help me out in this!!!!!!!!!!!
Thanks in Advance
To print the last 13 characters of a line:
echo "$string" | awk '{print substr($0,length-12)}'
To get the last characters after the slash:
echo ${string##*/}
with basename:
basename "$string"
or with sed:
echo "$string" | sed 's_.*/__'
Regards
echo ".R1/new/sv902a.01.per" | sed 's/\(.*\)\(.\{13\}\)$/\2/'
summer_cherry has a nice solution but lacks readability.
just to prove there is more than one sulution
get the last 13 characters:
echo ".R1/new/sv902a.01.per" | rev | cut -b-13| rev
get the filename:
FOO=".R1/new/sv902a.01.per"
echo ${FOO##*/*/}
Shorter :rolleyes:
echo ${FOO##*/}