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:
The output I would like is as follow:
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.
I couls understand your script but I think I don't understand it completely, I've modified to get all columns I want for a real file and some values doesn't appear for some lines. The goal is that if in a block appear all values the transposed line must contain all values that I want to print, if a block only contains certain values, the corresponding column must be empty. Below is a excerpt of a real inputfile that contains much more parameters that will be headers in the ourput (the real file contain many blocks and 1 million lines).
The modified version is as below:
Hello ctsgnb,
I've tried your scripts, the 1rst and 3rd work the 2nd I get errors. The thing is I don't understand your script too much to modifiy them in order to print the corresponding values for each parameter in red above.
The larger sample below shows only 2 blocks then the output would containd 2 lines plus the header (3 in total)
(the parameters I want to get the values from are in blue, the corresponding values I want from each parameter are in red )
The output for this 2 blocks would be:
I don't want you to do it for me, I want to understand your codes to be able to do it for myself, then I need to get the pattern in your logic to able to print more columns in the output. Please help me, thank you for all your help so far.
You certainly had the hang of it. Because there are so many more variables than in the original sample I now used an extra array, for safety (otherwise original field values might get overwritten. Also in your second sample records now have preamble, for which I introduced a new test statement to discard them:
I made a few minor changes to the choice of field, it is only a matter of counting. Perhaps you can try and test this and make further adaptations to suit your need.....
The code uses RS= which separates records on empty line (two consecutive newline characters). The first small awk discards any spurious spaces and/or tab characters on those empty lines..
Last edited by Scrutinizer; 03-24-2012 at 05:41 PM..
This User Gave Thanks to Scrutinizer For This Post:
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)
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)
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)
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)
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)
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)
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)
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)
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)