Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    7

    Question Unanswered: File parsing returning block of output.

    Need to parse file which returns a block of output and not just that line.
    Any direction is greatly appreciated.

    Say Input file is of the following format:

    NAME: SCAN1
    CONDITION: if(....)
    and (....)
    ACTION: z=2

    NAME: SCAN2
    CONDITION: if (...)
    ACTION: y=5
    x=2

    NAME: SCAN3
    CONDITION: if(.....)
    ACTION: x=4
    y=2

    NAME: SCAN4
    CONDITION: if(.....)
    ACTION: x=4


    Need to write a script which parses the above file and gives me the block of what NAME string was provided.

    e.g: If Input SCAN2, output should be :
    NAME: SCAN2
    CONDITION: if (...)
    ACTION: y=5
    x=2

    Then need to look it so I can pull multiple block of whatever input I provide.

    e.g:
    SCAN2
    SCAN4

    provides me with the following output:

    NAME: SCAN2
    CONDITION: if (...)
    ACTION: y=5
    x=2

    NAME: SCAN4
    CONDITION: if(.....)
    ACTION: x=4

  2. #2
    Join Date
    Oct 2003
    Posts
    19
    Hi
    Are all your blocks separated by the single blank line . ?

  3. #3
    Join Date
    Jul 2004
    Posts
    7
    Quote Originally Posted by saurav101
    Hi
    Are all your blocks separated by the single blank line . ?

    -----------------------
    Hi Saurav... Nope. The only common thing is that i need everything from NAME to ACTN that defines a block.

  4. #4
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    something to start with:

    Code:
    nawk -v name='SCAN2' $0 ~ ("^NAME:.*" name),/^ACTION/
    nawk -v name='SCAN3' $0 ~ ("^NAME:.*" name),/^ACTION/
    vlad
    +-----------------------+
    | #include <disclaimer.h> |
    +-----------------------+

  5. #5
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    to pull multiple blocks:
    Code:
    nawk -v name='(SCAN2|SCAN3)' $0 ~ ("^NAME:.*" name),/^ACTION/
    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
  •