I'm trying to set up a script that parses a string.
My loop is currently
while [ -n "$RAW" ]; do
// do some processing here
RAW=$(echo $RAW| sed -r 's/^.{15}//')
done
However, the script never seems to end
It is not ending because the sed expression is not correct. It expects minimum 15 characters and does not work for anything less than 15 chars. Try this:
RAW=$(echo $RAW| sed -r 's/^.{0,15}//')
// to #. Second, the sed command didn't work properly, so RAW is never changed, that's why it goes infinite loopIt might not end because of the logic inside your while loop.
You're doing to overwrite variable RAW:
RAW=$(echo $RAW| sed -r 's/^.{15}//')
Which means match and replace first 15 characters in original variable by empty string. What is there are only 10 characters left. In that sed won't match (and replace) and your varialbe RAW will remain at that value.
You probably want upto 15 characters from start to be replaced and if that's the case this is what you will need:
RAW=$(echo $RAW | sed -r 's/^.{1,15}//')