I have a string from a log that's the equivelent of this....
a="20131202"
I need to seperate it out in to the 3 components.
I am assuming sed is the tool
Can I get a little guidance?
Parameter expansion is a better tool:
a=20131202
year=${a:0:4}
month=${a:4:2}
day=${a:6:2}
An alternative using regular expressions:
[[ $a =~ (....)(..)(..) ]]
year=${BASH_REMATCH[1]}
month=${BASH_REMATCH[2]}
day=${BASH_REMATCH[3]}
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