09-08-2010
Help converting row data to columns
I've been trying to figure this out for a while but I'm completely stumped. I have files with data in rows and I need to convert the data to columns. Each record contains four rows with a "field name: value" pair. I would like to convert it to four columns with the field names as column headers and the data from each row in the record below the corresponding column header.
For example:
Original data:
First Name: Gary
Last Name: Larson
DOB: 01/01/2010
POB: US
First Name: Bill
Last Name: Waterson
DOB: 01/01/2009
POB: US
First Name: Scott
Last Name: Adams
DOB: 01/01/2007
POB: US
Convert it to:
First Name Last Name DOB POB
Gary Larson 01/01/2010 US
Bill Waterson 01/01/2009 US
Scott Adams 01/01/2007 US
I would like to know how to do this in awk or sed. Thanks in advance for the help.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated.
Input:
test_data_1
1 2 90%
4 3 91%
5 4 90%
6 5 90%
9 6 90%
test_data_2
3 5 92%
5 4 92%
7 3 93%
9 2 92%
1 1 92%
...
Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies
2. Shell Programming and Scripting
Hi
I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example.
The original data record should be some thing like this
60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies
3. Shell Programming and Scripting
Hi Friends
I have the following input data in 2 columns.
SNo 1
I1 Value
I2 Value
I3 Value
SNo 2
I4 Value
I5 Value
I6 Value
I7 Value
SNo 3
I8 Value
I9 Value
...............
................
SNo N (1 Reply)
Discussion started by: ks_reddy
1 Replies
4. Shell Programming and Scripting
Hi
I have a file containing some data as follows:
11-17-2010:13:26 64 4 516414 1392258
11-17-2010:13:26 128 4 586868 695603
11-17-2010:13:26 256 4 474937 1642294
11-17-2010:13:32 64 4 378715 1357066
11-17-2010:13:32 128 4 597981 1684006 ... (17 Replies)
Discussion started by: annazpereira
17 Replies
5. Shell Programming and Scripting
I have a file which looks like this:
/* ----------------- EDW$MOC139_R_NNA_BR_SUM_FACT2 ----------------- */
insert_job: EDW$MOC139_R_NNA_BR_SUM_FACT2 job_type: c
command: /home/btchproc/load_process/batch_files/batch_nna_brn_split_sum_fact2.sh m
machine: edwprod02.dsm.pwj.com
#owner:... (29 Replies)
Discussion started by: Gangadhar Reddy
29 Replies
6. Shell Programming and Scripting
Hi everyone..
I have a list of values in a file...
1.2345e-1
2.282828e+
3.2341e-1
1.1223445e-1
I am interested in converting this column to a row..
1.2345e-1 2.282828e+ 3.2341e-1 1.1223445e-1
can anyone pls help?? I am a liunx newbie..
Thanks.. (7 Replies)
Discussion started by: kjha
7 Replies
7. UNIX for Dummies Questions & Answers
Hi,
I have a tab-delimited file as follows:
1 1 2 2 3 3 4 4
a a b b c c d d
5 5 6 6 7 7 8 8
e e f f g g h h
9 9 10 10 11 11 12 12
i i j j k k l l
13 13 14 14 15 15 16 16
m m n n o o p p
The output I need is:
1 1 a a 5 5 e e 9 9 i i 13... (5 Replies)
Discussion started by: mvaishnav
5 Replies
8. Emergency UNIX and Linux Support
Sorry if I repost my question in this section, but I'm really in a hurry since I have to finish my work... :(
Dear community,
I have a table with two rows like:
Row1 Row2
======= =======
7,3 text 1
1,3 text 2
1,2,3 blabla
What i need to do is add/copy... (2 Replies)
Discussion started by: Lord Spectre
2 Replies
9. Shell Programming and Scripting
i have a file (csv or txt or anything which has 4 columns (id,name,number,location) and it contains data. i want to convert the data of specific columns like name to ooooo and number to 88888 matching the field length of that columns.
for example
if name column has
anthony which is 7, it should... (2 Replies)
Discussion started by: prajaktaraut
2 Replies
LEARN ABOUT CENTOS
funtablerowget
funtablerowget(3) SAORD Documentation funtablerowget(3)
NAME
FunTableRowGet - get Funtools rows
SYNOPSIS
#include <funtools.h>
void *FunTableRowGet(Fun fun, void *rows, int maxrow, char *plist,
int *nrow)
DESCRIPTION
The FunTableRowGet() routine retrieves rows from a Funtools binary table or raw event file, and places the values of columns selected by
FunColumnSelect() into an array of user structs. Selected column values are automatically converted to the specified user data type (and
to native data format) as necessary.
The first argument is the Fun handle associated with this row data. The second rows argument is the array of user structs into which the
selected columns will be stored. If NULL is passed, the routine will automatically allocate space for this array. (This includes proper
allocation of pointers within each struct, if the "@" pointer type is used in the selection of columns. Note that if you pass NULL in the
second argument, you should free this space using the standard free() system call when you are finished with the array of rows.) The third
maxrow argument specifies the maximum number of rows to be returned. Thus, if rows is allocated by the user, it should be at least of size
maxrow*sizeof(evstruct).
The fourth plist argument is a param list string. Currently, the keyword/value pair "mask=transparent" is supported in the plist argument.
If this string is passed in the call's plist argument, then all rows are passed back to the user (instead of just rows passing the filter).
This is only useful when FunColumnSelect() also is used to specify "$region" as a column to return for each row. In such a case, rows
found within a region have a returned region value greater than 0 (corresponding to the region id of the region in which they are located),
rows passing the filter but not in a region have region value of -1, and rows not passing any filter have region value of 0. Thus, using
"mask=transparent" and the returned region value, a program can process all rows and decide on an action based on whether a given row
passed the filter or not.
The final argument is a pointer to an int variable that will return the actual number of rows returned. The routine returns a pointer to
the array of stored rows, or NULL if there was an error. (This pointer will be the same as the second argument, if the latter is
non-NULL).
/* get rows -- let routine allocate the row array */
while( (buf = (Ev)FunTableRowGet(fun, NULL, MAXROW, NULL, &got)) ){
/* process all rows */
for(i=0; i<got; i++){
/* point to the i'th row */
ev = buf+i;
/* rearrange some values. etc. */
ev->energy = (ev->pi+ev->pha)/2.0;
ev->pha = -ev->pha;
ev->pi = -ev->pi;
}
/* write out this batch of rows */
FunTableRowPut(fun2, buf, got, 0, NULL);
/* free row data */
if( buf ) free(buf);
}
As shown above, successive calls to FunTableRowGet() will return the next set of rows from the input file until all rows have been read,
i.e., the routine behaves like sequential Unix I/O calls such as fread(). See evmerge example code for a more complete example.
Note that FunTableRowGet() also can be called as FunEventsGet(), for backward compatibility.
SEE ALSO
See funtools(7) for a list of Funtools help pages
version 1.4.2 January 2, 2008 funtablerowget(3)