Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    12

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

  2. #2
    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> |
    +-----------------------+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •