read specific text from a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read specific text from a log file
# 1  
Old 10-17-2006
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

Code:
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>

# 2  
Old 10-17-2006
i need to write a script that will retrieve those values in bold only in my previous post. pls help me. thanks
# 3  
Old 10-17-2006
Code:
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 "--------------"
# 4  
Old 10-17-2006
thanks anbu.. i will implement this.. and will let you know.
# 5  
Old 10-17-2006
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
Code:
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
Code:
CP_NUM_RUN_: 3
CP_MAX_TASK: 20

I did a set -x and i got the following

Code:
+ 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read all data after a specific string from a text file ?

Hi, I have a file(input.txt) and trying to format as output.txt. See the attached file format. Note: This is a windows file (DOS format) and the commands are also going to execute on windows. Basically I am trying to capture all the data in between Local Group Memberships and Global Group... (10 Replies)
Discussion started by: Monoj2014
10 Replies

2. Shell Programming and Scripting

Extract specific line in an html file starting and ending with specific pattern to a text file

Hi This is my first post and I'm just a beginner. So please be nice to me. I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file? I have tried sed -n 241,241p... (13 Replies)
Discussion started by: dejavo
13 Replies

3. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

4. Shell Programming and Scripting

How to read specific line of text from a Script and send email notification

Hi ! I am a newbie and never officially wrote a shell script before. The requirement for this script is : 1) Read a file called 'bpm.log' and identify if it has a specific text such as 'this is the text'. Its a static value and that is the only text we need to read. 2) If that... (2 Replies)
Discussion started by: atechcorp
2 Replies

5. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

6. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

7. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

8. UNIX for Dummies Questions & Answers

search and replace a specific text in text file?

I have a text file with following content (3 lines) filename : output.txt first line:12/12/2008 second line:12/12/2008 third line:Y I would like to know how we can replace 'Y' with 'N' in the 3rd line keeping 1st and 2nd lines same as what it was before. I tried using cat output.txt... (4 Replies)
Discussion started by: santosham
4 Replies

9. Shell Programming and Scripting

read space filled file and replace text at specific position

Hi I have a spaced filled file having records like below: What I want is to read line having RT3 at position 17-19 then go to position 2651 check the 18 characters (might be space filled till 18 characters). This position should have a... (6 Replies)
Discussion started by: COD
6 Replies

10. Shell Programming and Scripting

How to read a specific value from a Log file?

Hi, I have a .log file in which it has many values. But i need some specific values. How it can be done using Shell Script. Please explain in detail. Thankx in advance. Sathish D V. (8 Replies)
Discussion started by: cooolthud
8 Replies
Login or Register to Ask a Question