finding lines only between a certain string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding lines only between a certain string
# 1  
Old 10-20-2008
finding lines only between a certain string

Dear experts,

Ive been trying to figure this out for a while, but i cant. Please help.
I have a file, with approx 1 million lines. The contents are separated with "----------". Please see example below

Quote:
--------------------------------------------------------------------------------------------------------------------------
M-GET CONFIRMATION (
INVOKE IDENTIFIER 346,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS alarmRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341862
},
CURRENT TIME "20080626105012",
ATTRIBUTE LIST {
objectClass alarmRecord,
nameBinding logRecord-log,
managedObjectClass sypObjMAL,
managedObjectInstance { sypAlarmObjectId = "MAL" },
eventType communicationsAlarm,
eventTime "20080609032818",
logRecordId number : 341862,
loggingTime "20080609032819",
packages {
GAAGDA1C.correlatedNotificationsPackage,
GAAGDA1C.additionalInformationPackage, eventTimePackage
},
probableCause SAXBAA0C.lossOfSignal,
perceivedSeverity cleared,
correlatedNotifications { { correlatedNotifications { 23147 } } },
additionalInformation {
{
identifier alarmIdentification,
information AlarmIdentification : "CLASS=PCMMAL LTG=13-08 DIU=1"
}
}
}
)
--------------------------------------------------------------------------------------------------------------------------
M-GET CONFIRMATION (
INVOKE IDENTIFIER 347,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS alarmRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341863
},
CURRENT TIME "20080626105012",
ATTRIBUTE LIST {
objectClass alarmRecord,
nameBinding logRecord-log,
managedObjectClass chargingFailure,
managedObjectInstance { chargingFailureId = 1 },
eventType processingErrorAlarm,
eventTime "20080609173506",
logRecordId number : 341863,
loggingTime "20080609173507",
packages {
specificProblemsPackage, notificationIdentifierPackage,
proposedRepairActionsPackage, additionalTextPackage,
eventTimePackage
},
probableCause SAXBAA0C.storageCapacityProblem,
specificProblems { specProb-chargingFailure-sp5 },
perceivedSeverity critical,
notificationIdentifier 33589625,
proposedRepairActions { propRA-chargingFailure-alarm1 },
additionalText "SAMAR FULL : IA.ICITR"
}
)
--------------------------------------------------------------------------------------------------------------------------
So my problem is, i need to find all texts that have the keyword "GAA", but i need to see everything that is between the --------- lines. Desperatedly need a script to do this. Any help is appreciated. Thanks !
# 2  
Old 10-20-2008
Can you provide sample expected output.

Last edited by avis1981; 10-20-2008 at 01:06 AM.. Reason: Typo Error
# 3  
Old 10-20-2008
A sample expected output should be all lines in the file, which match the search pattern "GAA", and output in the format below

Quote:
--------------------------------------------------------------------------------------------------------------------------
M-GET CONFIRMATION (
INVOKE IDENTIFIER 109,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS stateChangeRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341650
},
CURRENT TIME "20080626105008",
ATTRIBUTE LIST {
objectClass stateChangeRecord,
nameBinding logRecord-log,
managedObjectClass KMMQGC0C.lic,

eventType stateChange,
eventTime "20080608013857",
logRecordId number : 341650,
loggingTime "20080608013857",
packages { eventTimePackage },
stateChangeDefinition {
{
attributeID GAAGDA1C.operationalState,
oldAttributeValue GAAASA1C.OperationalState : disabled,
newAttributeValue GAAASA1C.OperationalState : enabled
}
}
}
)
--------------------------------------------------------------------------------------------------------------------------
M-GET CONFIRMATION (
INVOKE IDENTIFIER 110,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS alarmRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341651
},
CURRENT TIME "20080626105008",
ATTRIBUTE LIST {
objectClass alarmRecord,
nameBinding logRecord-log,
managedObjectClass sypObjMAL,
managedObjectInstance { sypAlarmObjectId = "MAL" },
eventType communicationsAlarm,
eventTime "20080608013858",
logRecordId number : 341651,
loggingTime "20080608013859",
packages {
GAAGDA1C.correlatedNotificationsPackage,
GAAGDA1C.additionalInformationPackage, eventTimePackage
},
probableCause SAXBAA0C.lossOfSignal,
perceivedSeverity cleared,
correlatedNotifications { { correlatedNotifications { 29463 } } },
additionalInformation {
{
identifier alarmIdentification,
information AlarmIdentification : "CLASS=PCMMAL LTG=13-05 DIU=1"
}
}
}
)

--------------------------------------------------------------------------------------------------------------------------
M-GET CONFIRMATION (
INVOKE IDENTIFIER 109,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS stateChangeRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341650
},
CURRENT TIME "20080626105008",
ATTRIBUTE LIST {
objectClass stateChangeRecord,
nameBinding logRecord-log,
managedObjectClass KMMQGC0C.lic,

eventType stateChange,
eventTime "20080608013857",
logRecordId number : 341650,
loggingTime "20080608013857",
packages { eventTimePackage },
stateChangeDefinition {
{
attributeID GAAGDA1C.operationalState,
oldAttributeValue GAAASA1C.OperationalState : disabled,
newAttributeValue GAAASA1C.OperationalState : enabled
}
}
}
)
--------------------------------------------------------------------------------------------------------------------------
M-GET CONFIRMATION (
INVOKE IDENTIFIER 110,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS alarmRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341651
},
CURRENT TIME "20080626105008",
ATTRIBUTE LIST {
objectClass alarmRecord,
nameBinding logRecord-log,
managedObjectClass sypObjMAL,
managedObjectInstance { sypAlarmObjectId = "MAL" },
eventType communicationsAlarm,
eventTime "20080608013858",
logRecordId number : 341651,
loggingTime "20080608013859",
packages {
GAAGDA1C.correlatedNotificationsPackage,
GAAGDA1C.additionalInformationPackage, eventTimePackage
},
probableCause SAXBAA0C.lossOfSignal,
perceivedSeverity cleared,
correlatedNotifications { { correlatedNotifications { 29463 } } },
additionalInformation {
{
identifier alarmIdentification,
information AlarmIdentification : "CLASS=PCMMAL LTG=13-05 DIU=1"
}
}
}
)
--------------------------------------------------------------------------------------------------------------------------
# 4  
Old 10-20-2008
Try this:

Code:
awk '
        # new record, reset array index
        /^----/ { i=0 }
        # accumulate record contents in array
        { a[++i]=$0 }
        # matching record
        /GAA/ {
                # dump array contents
                for (j=1; j<=i; j++)
                        print a[j]
                # get the rest of this record
                while (getline && $0 !~ /^----/)
                        print
                # print the record terminator and reset the array
                print
                i=0
        }
' inputfile > outputfile

# 5  
Old 10-20-2008
Annihilannic,

Tried the script, it took about 3 mins to run, but no output. outputfile was empty Smilie
# 6  
Old 10-20-2008
Strange, works fine for me with the sample data you provided. What operating system are you using? Are there any spaces at the beginning of the lines?
# 7  
Old 10-20-2008
The file starts like this

Quote:
root@ckpgpay11core> more /tmp/AIALARM_MSNLA_20080626.txt
MSNLA/UCR40_23MSC_SSNC_EC1C00 6/26/2008 10:50:03 AM
8-15475 KPGCMCS01/AZAHXX#1

DISPEVREC:Event log=String : "AIALARM";
STARTED

Event log records
==================================================================================================== ======================
M-GET CONFIRMATION (
INVOKE IDENTIFIER 102,
LINKED IDENTIFIER 1,
MANAGED OBJECT CLASS alarmRecord,
MANAGED OBJECT INSTANCE {
logId = string : "AIALARM",
logRecordId = number : 341643
},
CURRENT TIME "20080626105008",
ATTRIBUTE LIST {
objectClass alarmRecord,
nameBinding logRecord-log,
managedObjectClass sypObjMAL,
managedObjectInstance { sypAlarmObjectId = "MAL" },
eventType communicationsAlarm,
eventTime "20080608013830",
logRecordId number : 341643,
loggingTime "20080608013832",
packages {
notificationIdentifierPackage,
GAAGDA1C.additionalInformationPackage, eventTimePackage
},
probableCause SAXBAA0C.lossOfSignal,
perceivedSeverity major,
notificationIdentifier 20195,
additionalInformation {
Im using solaris 9
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

2. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

3. Shell Programming and Scripting

finding least out of selected lines

Hello, I have a file, which looks like: I want to print the row containg "PRO" in second column after comparing and finding the minimum value of fifth column present in all "PRO". and likewise for every other string present in second column. I am using : filename=list... (2 Replies)
Discussion started by: CAch
2 Replies

4. Shell Programming and Scripting

Printing all lines before a specific string and a custom message 2 lines after

Hello all, I need to print all the lines before a specific string and print a custom message 2 lines after that. So far I have managed to print everything up the string, inclusively, but I can't figure out how to print the 2 lines after that and the custom message. My code thus far is:... (4 Replies)
Discussion started by: SEinT
4 Replies

5. Shell Programming and Scripting

Finding a string with another string is found

finding a string with another string is found EX: abs c/- i want to find /-, then copy abs. i know it's easy use awk, but my problem is the substr syntax. substr($2,2,2) will give me /- but the conflict is /- is not always the second characted of the second string. (11 Replies)
Discussion started by: engr.jay
11 Replies

6. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

7. Shell Programming and Scripting

Reading n number of lines after finding string

I am trying to search a file for a value: "Top 30 reject reasons" and want the next 30 lines after that and output in a text file. If I knew the line number, I can use a combination of head and tail commands to get my results, but this doesn't seem to work when I don't have a line number. I... (2 Replies)
Discussion started by: oriqin
2 Replies

8. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

9. Emergency UNIX and Linux Support

Getting last 50 lines after finding a word

Hi All, I have a requirement as below I need find for a string in a log file and once i found that string i need to send a mail.Thsi can be done thru grep and mailx cmnd. Here once i found the string i need to send last 50 lines(up) from where string found. Actually they require to find... (9 Replies)
Discussion started by: pssandeep
9 Replies

10. Shell Programming and Scripting

help with finding a string

Hello folks I have a text file abcd.txt and has a line starting with number '8'. I have a string in this line starting at position 'a' to position 'b' also this string is a number and have to be reduced by 1. there is also a problem that it has to be padded with zeros to make the string... (2 Replies)
Discussion started by: sandyg
2 Replies
Login or Register to Ask a Question