show your "home work" code to we can see it then / and try to figure out your logic and method you're using to try and get whatever you're doing, done.
PATTERNS, very important. Always look for a patten you can use when dealing with strings, and data extraction, and replacements. You have a string that looks to be a set pattern with parts of it that may change, The parts you put in bold are your changing parts these are not the pattern, because it changes, the pattern is the part of it that stays constant through out the entire run of what you're doing.
So you're going to need to use the pattern and something that will complement that. Seeings that you're needing the the data that is going to be an unknown at all times. Use the Pattern to find your changing data, then use that pattern for your set point, then look ahead or behind it depending on which end of the string you're attacking to get your data.
BASH Scripting example.
Code:
#!/bin/bash
data_string="INDEX_VALUE_id65_p225_TOTAL_TIME_100h30m52S_POSITION_1234p5p8"
#cut off left side
var1=${data_string/INDEX_VALUE_/}
echo $var1
#take remainder then cut off right side
var1=${var1%_TOTAL*}
#final results
echo $var1
Results.
Code:
$ ./get_data
id65_p225_TOTAL_TIME_100h30m52S_POSITION_1234p5p8
id65_p225
No matter what the INDEX VALUE is you're always going to get it using the patterns and string manipulation.
You have basically two types to deal with. The one where you have to find a pattern then look ahead or behind it, then get that information.or replace it, or look for the information itself and get that information, or replace it. All depending on its pattern.
Does not matter if you're using BASH, sed, awk, perl, ect.. PATTERNS are very important. Familiarize yourself with finding patterns. Then figure out what is the best tool to use.
you also can use character count which is also a type of pattern in itself. Using string manipulation, ending with this.
Code:
var1=id65_p225
var2=100h30m52S
var3=1234p5p8
http://tldp.org/LDP/abs/html/string-manipulation.html