Find the answer to your Linux question:
Results 1 to 3 of 3
Gurus, My input file has the format as below: some text some text some text Applications: ------------- some text ----------------------- Transactions: ------------- some text ----------------------- BufferPools: ------------- some text ----------------------- ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    5

    how to put the text between two key words into a file

    Gurus,
    My input file has the format as below:

    some text
    some text
    some text
    Applications:
    ------------- some text -----------------------
    Transactions:
    ------------- some text -----------------------
    BufferPools:
    ------------- some text -----------------------
    Logs:
    ------------- some text -----------------------
    Locks:
    ------------- some text -----------------------
    Tablespace Configuration:
    ------------- some text --------------------------
    Tablespace Statistics:
    ------------- some text --------------------------
    Tablespace Autoresize Statistics:
    ------------- some text --------------------------
    Containers:
    ------------- some text --------------------------
    Dynamic Cache:
    ------------- some text --------------------------
    Dynamic SQL Statements:
    ------------- some text --------------------------
    Dynamic SQL Environments:
    ------------- some text --------------------------
    Dynamic SQL Variations:
    ------------- some text --------------------------

    I would like to split this file into multiple parts. For example, I need the text between "Locks:" and "Tablespace Configuration:" in one file. How do I do this ?
    To be more clear, I need the "locksfile" to start with "Locks:" and put the text (into locksfile) following "Locks:" key word till it encouters the next key word like "Tablespace Configuration:".

    Thanks a lot.

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Some pseudocode:
    Code:
    while there are lines to read, do:
        line := readLine()
        if isKeyword(line), then:
            closeCurrentlyOpenFile()
            file := openFileForKeyword(line)
            printToFile(file, line)
        else:
            printToFile(file, line)
    Does this make sense?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    26
    Quote Originally Posted by beowulfkid View Post
    Gurus,
    My input file has the format as below:

    some text
    some text
    some text
    Applications:
    ------------- some text -----------------------
    Transactions:
    ------------- some text -----------------------
    BufferPools:
    ------------- some text -----------------------
    Logs:
    ------------- some text -----------------------
    Locks:
    ------------- some text -----------------------
    Tablespace Configuration:
    ------------- some text --------------------------
    Tablespace Statistics:
    ------------- some text --------------------------
    Tablespace Autoresize Statistics:
    ------------- some text --------------------------
    Containers:
    ------------- some text --------------------------
    Dynamic Cache:
    ------------- some text --------------------------
    Dynamic SQL Statements:
    ------------- some text --------------------------
    Dynamic SQL Environments:
    ------------- some text --------------------------
    Dynamic SQL Variations:
    ------------- some text --------------------------

    I would like to split this file into multiple parts. For example, I need the text between "Locks:" and "Tablespace Configuration:" in one file. How do I do this ?
    To be more clear, I need the "locksfile" to start with "Locks:" and put the text (into locksfile) following "Locks:" key word till it encouters the next key word like "Tablespace Configuration:".

    Thanks a lot.

    BEGIN {
    oktoprint=0;
    }
    {
    if ($0=="Locks:") {
    oktoprint=1;
    }
    if ($0=="Tablespace Configuration:") {
    oktoprint=0;
    }
    if (oktoprint==1) {
    print $0;
    }
    }

    'course that's only for one file though...

Posting Permissions

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