Sponsored Content
Top Forums Shell Programming and Scripting Transpose info that is within blocks Post 302611935 by Ophiuchus on Saturday 24th of March 2012 12:24:03 AM
Old 03-24-2012
Transpose info that is within blocks

Hello to all in forum,

I have a big file with blocks of data. Each block begins with "BeginOfRecord". There are blank lines
separating each block. I would like to transpose the info within each block in order to have each
blockīs info in a single line using awk but I don't know how to do it, I hope some awk expert could help me.

The input file looks like this:

Code:
 BeginOfRecord                                                 x( 0)-(SEQUENCE)   -> 000000:              
   A0820133                                                                                                 
      MSTerminating                                                x( 4)-(SEQUENCE)   -> 000004:              
      A482012F                                                                                                
        ChargeableDuration                                       x( 13)-(PARENT)     -> 00000C:             
        8D03                                                                                                
          .Time                                                  u( -1)-(BYTE)                              
            .Hour                       : 00                     k( -1)-(INT)        -> 00000E:             
            00                                                                                              
            .Minute                     : 01                     k( -1)-(INT)        -> 00000F:             
            01                                                                                              
            .Second                     : 11                     k( -1)-(INT)        -> 000010:             
            0B                                                                                              
        RecordSeqNumber                 : 123DED                 x( 2)-(BYTE)       -> 00002C:                     
        DateForStartOfCharge                                     x( 10)-(PARENT)     -> 000011:             
        8A03                                                                                                
          .Date                         : 20120313               k( -1)-(DATE)       -> 000013:             
          0C030D                                                                                            
        ExIdentity                      : ABRMMG2_ARI11_L        x( 10)-(ASCII)      -> 00091F:             
        EMLPPPriorityLevel              : 01                     x( 74)-(BYTE)       -> 000130:             
        9F4A0101                                                                                                     
                                                                                                            
                                                                                                            
   BeginOfRecord                                                 x( 0)-(SEQUENCE)   -> 000914:              
   A081A9                                                                                                   
      SSProcedure                                              x( 7)-(SEQUENCE)   -> 000917:                
      A781A6                                                                                                
        DateForStartOfCharge                                     x( 6)-(PARENT)     -> 00091A:              
        8603                                                                                                
          .Date                         : 20120207               k( -1)-(DATE)       -> 00091C:             
          0C030D                                                                                            
        ExIdentity                      : KULMMG5_ARI56_T        x( 10)-(ASCII)      -> 00091F:

The output I would like is as follow:

Code:
Type Of Record|ChargeableDuration|RecordSeqNumber|DateForStartOfCharge|ExIdentity                      
  MSTerminating|00:01:11|123DED|20120313|ABRMMG2_ARI11_L                                                 
  SSProcedure|||20120207||KULMMG5_ARI56_T

As you can notice, the texts in left side of input file become in headers (like 1rst line in blue) and some of those values
not always appears in all blocks, then if a value is not present the corresponding column will be blank, like in 3rd line.

Many thanks in advance for any help.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete blocks with no data..

Hi, I tried this but could not get it... here is what I need I have an xml where I get all the data in blocks but some times I get empty blocks with no data...shown below..I need to delete only those blocks with no data, I tried couple of ways but could not do it..any help is appreciated...... (1 Reply)
Discussion started by: mgirinath
1 Replies

2. Shell Programming and Scripting

How to read text in blocks

Hi, I have file which contains information written in blocks (every block is different). Is it possible to read every block one by one to another file (one block per file). The input is something like this <block1> <empty line> <block2> <empty line> ... ... ... <block25> <empty... (0 Replies)
Discussion started by: art84_)LV
0 Replies

3. Shell Programming and Scripting

Removing blocks from a file

I have a file like the one below. Each record is separated with > In between I have lines consisting of 3 numeric values separated by a space. I need to take each block between the > sign and read the first number in the line. Then take the first after the > sign and the last before the >... (7 Replies)
Discussion started by: kristinu
7 Replies

4. Shell Programming and Scripting

Help with Script using Command Blocks

Hello, I am trying to create a shell script that use command block (donīt really know if this is the correct way to say it), but while one version works fine, the other one is not working at all. So let me show an example of this "command block" Iīm using and its working ok: cat << _EOF_ `echo... (7 Replies)
Discussion started by: Alexis Duarte
7 Replies

5. UNIX for Dummies Questions & Answers

Convert 512-blocks to 4k blocks

I'm Unix. I'm looking at "df" on Unix now and below is an example. It's lists the filesystems out in 512-blocks, I need this in 4k blocks. Is there a way to do this in Unix or do I manually convert and how? So for container 1 there is 7,340,032 in size in 512-blocks. What would the 4k block be... (2 Replies)
Discussion started by: rockycj
2 Replies

6. Shell Programming and Scripting

how to split this file into blocks and then send these blocks as input to the tool called Yices?

Hello, I have a file like this: FILE.TXT: (define argc :: int) (assert ( > argc 1)) (assert ( = argc 1)) <check> # (define c :: float) (assert ( > c 0)) (assert ( = c 0)) <check> # now, i want to separate each block('#' is the delimeter), make them separate files, and then send them as... (5 Replies)
Discussion started by: paramad
5 Replies

7. Shell Programming and Scripting

Transpose lines from individual blocks to unique lines

Hello to all, happy new year 2013! May somebody could help me, is about a very similar problem to the problem I've posted here where the member rdrtx1 and bipinajith helped me a lot. https://www.unix.com/shell-programming-scripting/211147-map-values-blocks-single-line-2.html It is very... (3 Replies)
Discussion started by: Ophiuchus
3 Replies

8. Shell Programming and Scripting

Row blocks to column blocks

Hello, Searched for a while and found some "line-to-column" script. My case is similar but with multiple fields each row: S02 Length Per S02 7043 3.864 S02 54477 29.89 S02 104841 57.52 S03 Length Per S03 1150 0.835 S03 1321 0.96 S03 ... (9 Replies)
Discussion started by: yifangt
9 Replies

9. Shell Programming and Scripting

Blocks into table

please help, I have a huge file with blocks of data which I need to convert to a tabular format. Input sample id: GO:0000017 name: alpha-glucoside transport namespace: biological_process def: "The directed movement of alpha-glucosides into, out of or within a cell, or between... (3 Replies)
Discussion started by: ritakadm
3 Replies
All times are GMT -4. The time now is 09:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy