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

    Unanswered: Transpose rows into columns

    Needed to transpose rows into columns for the following file using any unix util. Any guidance will be greatly appreciated. I am stucked using awk and tried quite a few things to no avail. I could transpose the rows into Columns but could not break to new line when found a similar field.


    INPUT FILE

    %FIELD XXXX
    %TYPE s
    %ERRSW Y
    %TABLENUM 804
    %FIELD YYYY
    %TYPE s
    %ERRSW Y
    %TABLENUM 803
    %PERMVAL x"FFFFFF"
    %FIELD ZZZZ
    %TYPE s
    %ERRSW Y
    %TABLENUM 803
    %PERMVAL x"FFFFFF"


    OUTPUT

    %FIELD %TYPE %ERRSW %TABLENUM %PERMVAL

    XXXX s Y 804
    YYYY s Y 803 x"FFFFFF"
    ZZZZ s Y 803 x"FFFFFF"
    Last edited by ontoes6; 07-02-04 at 18:57. Reason: Resize document

  2. #2
    Join Date
    Sep 2007
    Posts
    1
    i am glad to join u

  3. #3
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    You can do something like that :
    Code:
    function print_line() {
       if (field) print field, type, errsw, tablenum, permval;
       field = type = errsw = tablenum = permval = "";
    }
    
    BEGIN { print "%FIELD","%TYPE","%ERRSW","%TABLENUM","%PERMVAL" }
    
    $1 == "%FIELD"    { print_line(); field    = $2 }
    $1 == "%TYPE"     {               type     = $2 }
    $1 == "%ERRSW"    {               errsw    = $2 }
    $1 == "%TABLENUM" {               tablenum = $2 }
    $1 == "%PERMVAL"  {               permval  = $2 }
    
    END { print_line() }
    Jean-Pierre.

Posting Permissions

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