I have string say,
a="abc_def ghi__333_31122013_Monthly.pdf"
I need the substract monthly and 31122013 from the above string in shell script. Basically doing substring from last till the first index of '_'.
Any help or suggestion is welcome.
Navdeep
Using awk:
a="abc_def ghi__333_31122013_Monthly.pdf"
awk -F '[_.]' '{print $(NF-2), $(NF-1)}' <<< "$a"
31122013 Monthly
Using IFS in BASH:
IFS=[_.] && arr=($a)
l=${#arr[@]}
echo ${arr[$l-3]}
31122013
echo ${arr[$l-2]}
Monthly
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments