CRC64
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
x=${x##*}
should be
x=${x##*
}
To remove everything up to the last newline in the first $offset characters of $input
should be
x=${x##*
}
To remove everything up to the last newline in the first $offset characters of $input
ASKER
Thank You
ASKER
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]*}