Find a regular expression on a line given the character offset of that line

The problem I face is easier to explain with an example:

 if given the offset position of letter "h"  that is 6, return number 105
 if given the offset position of letter "s"  that is 57, return number 107

Here is the input text:
___________________________
105  hello world

106  today is friday
107  tomorrow is saturday
___________________________

I am using bash.

I found that  using "expr substr" I can locate the character at the given offset, but don't know how to proceed from there using grep.  I am happy with using other tools (sed - my preference- or awk ). If it has to be done with perl  I am happy to go that way to but I do not have experience with that language.

The regular expression would be "^[0-9]* "  that is a number followed by a space

Many thanks in advance for your help
CRC64Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
#!/bin/bash
input='105  hello world

106  today is friday
107  tomorrow is saturday
'
for offset in 6 57 ; do
  x=${input:0:$offset}
  x=${x##*
}
  echo ${x%%[^0-9]*}
done
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CRC64Author Commented:
Fantastic!

 Can you please explain the 3 lines of code below (or tell me which feature to look for) ?

  x=${input:0:$offset}

   x=${x##*}

  echo ${x%%[^0-9]*}
0
ozoCommented:
x=${x##*}
should be
x=${x##*
}
To remove everything up to the last newline in the first $offset characters of $input
0
CRC64Author Commented:
Thank You
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.