If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > RE grep question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-02-04, 12:57
kasparaitis kasparaitis is offline
Registered User
 
Join Date: Sep 2003
Posts: 12
RE grep question

Hello,

I need some help trying to grep from a specific point in a file(part of a name) up until another name. I want to grab anything containing segment "what ever the user chooses to input" up until the statistics portion of the file and place these in another file. I also need these to stay in the same order as the orginal file. The file that I am grep'ing through is pasted below. The only difference is the original has thousands of these segments in it.

I can only grep out specific file names, any other variation I've tried gives me everything listed in the file.

}
segment "THIS" {
agentAddress "111.111.111.111"
uniqueDeviceId "11:11:11:11:11:11"
mibTranslationFile "asdfasdfasdfasdf.mtf"
index "9"
statistics "1"
deviceSpeed "10000000.0"
discoverMtf "asdfasdf.mtf"
sysDescr "Cisco Systems Catalyst 1900"
sysName "yadayada"
sysLoc "12345 wilshire"
sysContact "Joe Schmoe"
ifDescr "1 "
ifType "asdfasdfasdfasdf"
nmsName "asdfasdfasdfasdf"
enterpriseId "9"
ifPhysAddress "asdfasdfasdf"
community "asdfadsf"
}
segment "That" {
agentAddress "111.111.111.111"
uniqueDeviceId "11:11:11:11:11:11"
mibTranslationFile "asdfasdfasdfasdf.mtf"
index "9"
statistics "1"
deviceSpeed "10000000.0"
discoverMtf "asdfasdf.mtf"
sysDescr "Cisco Systems Catalyst 1900"
sysName "yadayada"
sysLoc "12345 wilshire"
sysContact "Joe Schmoe"
ifDescr "1 "
ifType "asdfasdfasdfasdf"
nmsName "asdfasdfasdfasdf"
enterpriseId "9"
ifPhysAddress "asdfasdfasdf"
community "asdfadsf"
}
segment "blah_blah" {
agentAddress "111.111.111.111"
uniqueDeviceId "11:11:11:11:11:11"
mibTranslationFile "asdfasdfasdfasdf.mtf"
index "9"
statistics "1"
deviceSpeed "10000000.0"
discoverMtf "asdfasdf.mtf"
sysDescr "Cisco Systems Catalyst 1900"
sysName "yadayada"
sysLoc "12345 wilshire"
sysContact "Joe Schmoe"
ifDescr "1 "
ifType "asdfasdfasdfasdf"
nmsName "asdfasdfasdfasdf"
enterpriseId "9"
ifPhysAddress "asdfasdfasdf"
community "asdfadsf"
}

Thanks in advance,

Kasparaitis
Reply With Quote
  #2 (permalink)  
Old 11-02-04, 13:32
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
something like this? (to get the block of "THIS" segment)

nawk -v segName="THIS" -f kasp.awk myFile.txt > segmentTHIS.out

Code:
BEGIN {
   FS=ORS=""
   OFS="\n"
   RS="}"
}
$1 ~ ("^segment.*" segName) {$1=""; print}
__________________
vlad
+-----------------------+
| #include <disclaimer.h> |
+-----------------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On