Pull a string out of a string in a shell script

I have a linux shell script that contains a variable with a very long string in it.  I need to pull a string out of that very long string.  The string will start with "oct 19" and end with "blahblah".  But the number of characters in between will vary.  How do I extract the string?
serjoshAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Tyler LaczkoCommented:
$mystring = "long string oct aklsdfgklajg akgjasdgjka blah asdgasdg";
//split into 2 parts
@s_array1 = split("oct", $mystring);
split into 2 parts
@s_array2 = split("oct", @s_array1[1]);

print @s_array2[0];
0
Tyler LaczkoCommented:
$mystring = "long string oct aklsdfgklajg akgjasdgjka blah asdgasdg";
//split into 2 parts
@s_array1 = split("oct 19", $mystring);
split into 2 parts
@s_array2 = split("blahblah", @s_array1[1]);

print @s_array2[0];
0
Tyler LaczkoCommented:
$mystring = "long string oct aklsdfgklajg akgjasdgjka blah asdgasdg";
//split into 2 parts
@s_array1 = split("oct 19", $mystring);
//split into 2 parts
@s_array2 = split("blahblah", @s_array1[1]);

print @s_array2[0];
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

serjoshAuthor Commented:
Professionalcomputersolutions,
I get all kinds of errors in my shell script after I put your code into it.

./Cgrep.sh: line 11: =: command not found
./Cgrep.sh: line 12: //split: No such file or directory
./Cgrep.sh: line 13: syntax error near unexpected token `('
./Cgrep.sh: line 13: `@s_array1 = split("oct 19", $mystring);'
0
Tyler LaczkoCommented:
lol

dont just copy and paste my code.

look at it and read it then write your own code.

mine is just an algorithm

Declare your long string
Split the string into 2 parts
you will now have 2 strings 1st is garbage 2nd is the start of what you want to the very end
split the 2nd string into 2 parts
you will have 2 more strings the first contains the info you want the second is garbage

use the string in pos 0 of the second array.
0
TintinCommented:
Simply do

grep -Eo "oct 19.*blahblah" file
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
serjoshAuthor Commented:
I guess the 'split' function is the part that is confusing me.  This is a bash shell script.  Can the unix split command be used the way you are saying?  It seems it's used to split files not strings?  I get errors every time i try to use it.  perhaps you could give me a little more verbose description of how I can accomplish this?  Sorry for my confusion =P
0
TintinCommented:
professionalcomputersolutions gave you Perl code, not shell script.

Just use my grep solution.  Much easier :)
0
serjoshAuthor Commented:
That seems to have done it, thanks!
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
Programming

From novice to tech pro — start learning today.