On Fri, Jul 3, 2009 at 9:08 AM, Kyle <[email protected]> wrote:
> Hi Folks,
>
> I am trying to extract a substring from a string found in a file.
>
> The string is: *** End of TF0220 at Thu Jul 2 10:06:51 EST 2009 - RC
> = 0
>
> and the substring I want to extract is TF0220. This is a program name and
> the length of this name varies. In other words I want to extract whatever is
> between the words "of" and "at" in a script.
If the name is always at the same position in the string(ie, the line always
starts with "*** End of " - "awk '{ print $4 ;}'" will do most of what you
want.
saga:~/src polleyj$ echo '*** End of TF0220 at Thu Jul 2 10:06:51 EST
2009 - RC = 0' | awk '{ print $4 ;}'
TF0220
You probably want to do something extra to select out only lines matching
this pattern - you can do this by stipulating a match to awk - ie, make it
"awk '/End of/ { print $4; }'"
>
> How would I likely go about that please?
>
> --
> ------------------------------------------------------------------------
> Kind Regards
>
> Kyle
>
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html