I have a variable as
string="ABC400p2q4".
how can I separate ABC400
and p2q4
.
I need to separate it in two variables in such a way that as a result I get
echo $var1
ABC400
echo $var2
p2q4
In place of ABC there can be any alphabetic characters; in place of 400 there can be any other digits; but p
and q
are fixed and in place of 2 and 4 as well there can be any digit.
No need to split based on a regexp pattern as they are fixed length substrings. In pure bash
you would do:
$ string="ABC400p2q4"
$ var1=${string:0:6}
$ var2=${string:6}
$ echo $var1
ABC400
$ echo $var2
p2q4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With