I have a regex, and it is working as intended here: https://regex101.com/r/fR4mI1/1
It finds all integers 1-9, but not zero, or more accurately, it finds Not non digits nor 0. That is exactly what I have going on below, but it isn't working out that way. I have 0's from my input showing up in my output in strange ways. Everything else I'm trying to do is working fine, but I don't want any zeros at all. What am I doing wrong?
#!/bin/bash
#not non-digits or 0, replace with capture and new line
#due to confusion, yes I've tried [1-9] same result
#I understand the statement is not intuitive, that's why I clarified in my explanation
nums=$(echo 821312010476 | sed -r 's/([^\D0])/\1\n/g')
declare -a array
#make array
#error
# 01 and 04 from string above return as 01 and 04 and not 1 or 4
#why are there 0's still?
for num in $nums; do
echo $num
array+=($num)
done
for ((index= 0; index <=${#array[@]}; index++)); do
#make string of 2 integer chars to see if value is within range
myTempNum="${array[index]}${array[index+1]}"
if [[ myTempNum -gt 0 && myTempNum -lt 30 ]]
then
echo $myTempNum
index=$index+1
elif [[ ${array[index]} -gt 0 ]]
then
echo ${array[index]}
fi
done
example output
8
2
1
3
1
2
01
04
7
6
8
21
3
12
01
04
7
6
you can see the 01 and 04 here both times