read specific text from a log file

Hi guys

I need to retrieve the values in BOLD that I have mentioned in the below log file. I want to store those values in a variable, preferably the same name as the column name in the log file. if you paste the below mentioned log file in a notepad and remove the word wrap.. u will get a better idea.. thanks

Siebel Enterprise Applications Siebel Server Manager, Version 7.5.3.12 [16272] LANG_INDEPENDENT 
Copyright (c) 2001 Siebel Systems, Inc.  All rights reserved.

This software is the property of Siebel Systems, Inc., 2207 Bridgepointe Parkway,
San Mateo, CA 94404.

User agrees that any use of this software is governed by: (1) the applicable
user limitations and other terms and conditions of the license agreement which
has been entered into with Siebel Systems or its authorized distributors; and
(2) the proprietary and restricted rights notices included in this software.

WARNING: THIS COMPUTER PROGRAM IS PROTECTED BY U.S. AND INTERNATIONAL LAW.
UNAUTHORIZED REPRODUCTION, DISTRIBUTION OR USE OF THIS PROGRAM, OR ANY PORTION
OF IT, MAY RESULT IN SEVERE CIVIL AND CRIMINAL PENALTIES, AND WILL BE
PROSECUTED TO THE MAXIMUM EXTENT POSSIBLE UNDER THE LAW.

If you have received this software in error, please notify Siebel Systems
immediately at (650) 295-5000.

Type "help" for list of commands, "help <topic>" for detailed help

Connected to 1 server(s) out of a total of 1 server(s) in the enterprise

srvrmgr:sble01> list component 'eCustomerCMEObjMgr_enu'

SV_NAME  CC_ALIAS                CC_NAME                                              CT_ALIAS  CG_ALIAS        CC_RUNMODE CP_DISP_RUN_STATE  CP_NUM_RUN_   CP_MAX_TASK   CP_ACTV_MTS  CP_MAX_MTS_  CP_START_TIME        CP_END_TIME  CP_STATUS  CC_INCARN_NO  CC_DESC_TEXT  
-------  ----------------------  ---------------------------------------------------  --------  --------------  -----------  -----------------  -----------  -----------  -----------  -----------  -------------------  -----------  ---------  ------------  ------------  
sble01   eCustomerCMEObjMgr_enu  eCustomer Power Communications Object Manager (ENU)            Communications  Interactive  Running            4             20            1            1            2006-10-16 12:27:03                                                      

1 row returned.

srvrmgr:sble01> 

i need to write a script that will retrieve those values in bold only in my previous post. pls help me. thanks

sed -n "/CP_NUM_RUN_/,/rows* returned./p" file |
awk -v var1="CP_NUM_RUN_" -v var2="CP_MAX_TASK" '
$0 ~ var1 { 
flag=1
ind1=index($0,var1);ind2=index($0,var2);
for(i=1;i<=NF;++i)
{
        if( $i == var1 ) fld1=i;
        if( $i == var2 ) fld2=i;
}
getline
len1=length($fld1)
len2=length($fld2)
getline
}
flag == 1 {
print var1 ": " substr($0,ind1,len1) "\n" var2 ": " substr($0,ind2,len2)
}' 

Above code will work only if the value of field aligns with "--------------"

thanks anbu.. i will implement this.. and will let you know.

hi anbu,

i implemented your code. i just did a small change. i changed 'awk' to 'nawk' because its solaris OS. I didnt get the output when i used 'awk'.

the output of my code is as follows

CP_NUM_RUN_: 3
CP_MAX_TASK: 20
CP_NUM_RUN_:
CP_MAX_TASK:
CP_NUM_RUN_:
CP_MAX_TASK:

I want my output to be like this

CP_NUM_RUN_: 3
CP_MAX_TASK: 20

I did a set -x and i got the following

+ nawk -v var1=CP_NUM_RUN_ -v var2=CP_MAX_TASK
$0 ~ var1 {
flag=1
ind1=index($0,var1);ind2=index($0,var2);
for(i=1;i<=NF;++i)
{
        if( $i == var1 ) fld1=i;
        if( $i == var2 ) fld2=i;
}
getline
len1=length($fld1)
len2=length($fld2)
getline
}
flag == 1 {
print var1 ": " substr($0,ind1,len1) "\n" var2 ": " substr($0,ind2,len2)
}
CP_NUM_RUN_: 3
CP_MAX_TASK: 20
CP_NUM_RUN_:
CP_MAX_TASK:
CP_NUM_RUN_:
CP_MAX_TASK:
+ exit

I appreciate your help very much. pls help me with it.