Sponsored Content
Top Forums Shell Programming and Scripting Extract difference of two columns from different rows Post 302398247 by sam_2921 on Wednesday 24th of February 2010 05:22:00 AM
Old 02-24-2010
Bug Extract difference of two columns from different rows

Hello guys,

Please help me to solve this problem. I have tried some awk commands but couldn't succeed.
I have a tab delimited file where each record is separated by ------ and 4th column of each record is same.

<INPUT FILE>
Code:
------
peon    53931587        53931821        Health=max01g42730.1
------
SDS     53931589        53931821        Health=max01g42730.1
peon    53932031        53932091        Health=max01g42730.1
SDS     53932031        53932091        Health=max01g42730.1
peon    53932827        53932904        Health=max01g42730.1
SDS     53932827        53932904        Health=max01g42730.1
peon    53933029        53933144        Health=max01g42730.1
SDS     53933029        53933144        Health=max01g42730.1
peon    53933271        53933610        Health=max01g42730.1
------
peon    53931587        53931821        Health=max01g52340.2
------
SDS     39623053        39623169        Health=max05g35620.1
peon    39623246        39623350        Health=max05g35620.1
SDS     39623246        39623350        Health=max05g35620.1
peon    39623990        39624103        Health=max05g35620.1

I want an output file where rows are added corresponding to each record. An examlpe output file is -
Code:
------
zxy    0    Health=max01g42730.1
------
zxy    210    Health=max01g42730.1
zxy    736    Health=max01g42730.1
zxy    125    Health=max01g42730.1
zxy    127    Health=max01g42730.1
------
zxy    0    Health=max01g52340.2
------
zxy    77    Health=max05g35620.1
zxy    640    Health=max05g35620.1

Here, 3rd column is same as 4th column of input file
2nd column is calculated by subtracting 3rd column of row starting with SDS
from 2nd column of row starting with peon i.e. (53932031-53931821 = 210) in case of second record. This has to be calculated for all the
SDS-peon pairs in each record. Value zero is assigned if there is only 1 row in a record i.e. SDS-peon pair is missing.

Thanks in advance.

Last edited by sam_2921; 02-24-2010 at 06:39 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difference between two rows

Dears, I have a list as follows, 2 4 8 If I want to find the difference between two consecutive rows. Then I have to store the specific rows in two variables and then find the difference. Could someone tell how this can be done. Regards, (7 Replies)
Discussion started by: JimJim
7 Replies

2. Shell Programming and Scripting

Difference between corresponding elements of successive rows

Hi, I have a file in the following format a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4 I need a script to find the difference between corresponding values of successive rows. So the output would have one less row than the input file and should look like: a2-a1 b2-b1 c2-c1 d2-d1... (4 Replies)
Discussion started by: sajal.bhatia
4 Replies

3. Shell Programming and Scripting

Extract values from a matrix given the rows and columns

Hi All, I have a huge (and its really huge!) matrix about 400GB in size (2 million rows by 1.5 million columns) . I am trying to optimize its space by creating a sparse representation of it. Miniature version of the matrix looks like this (matrix.mtx): 3.4543 65.7876 54.564 2.12344... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

4. Shell Programming and Scripting

Extract several columns with few rows

Hello, I want to extract several columns and rows from a huge tab delimited file for example: I want to print from from column 3 to 68 till row number 30. I have tried using cut command but it was extracting whole 3rd and 68th column. Please suggest a solution. Ryan (8 Replies)
Discussion started by: ryan9011
8 Replies

5. Shell Programming and Scripting

Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks

Hi Friends, I have come across some files where some of the columns don not have data. Key, Data1,Data2,Data3,Data4,Data5 A,5,6,,10,, A,3,4,,3,, B,1,,4,5,, B,2,,3,4,, If we see the above data on Data5 column do not have any row got filled. So remove only that column(Here Data5) and... (4 Replies)
Discussion started by: ks_reddy
4 Replies

6. UNIX for Dummies Questions & Answers

Finding difference in 1st field for rows of data

I have a file that has multiple lines, of grouped data, that typically all have the same values in the 1st field, however, I would like to search the 1st field for any differences and set a flag to use in an "if" statement to run some other routine. An example of the typical file is below,... (2 Replies)
Discussion started by: co21ss
2 Replies

7. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

8. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

9. Shell Programming and Scripting

Extract rows with different values at 2 columns

Hallo, I would need to extract only rows which has different value in the second and third column. Thank you very much for any advices Input: A 0 0 B 0 1 C 1 1 D 1 3 Output B 0 1 D 1 3 (4 Replies)
Discussion started by: kamcamonty
4 Replies

10. Shell Programming and Scripting

Calculating Time difference Between two Rows in Linux

16:45:51 10051 77845 16:45:51 10051 77845 16:46:52 10051 77846 16:46:53 10051 77846 Match the last PID then subtract second line time with first line. Please help me with any command or script. working in media company on a project OS: RHEl7 tried command: awk 'function... (2 Replies)
Discussion started by: vivekn
2 Replies
XDF_SET_CONF(3) 					     xdffileio library manual						   XDF_SET_CONF(3)

NAME
xdf_set_conf, xdf_get_conf - set or get the configuration of xDF file SYNOPSIS
#include <xdfio.h> int xdf_set_conf(struct xdf* xdf, enum xdffield field, ...); int xdf_get_conf(const struct xdf* xdf, enum xdffield field, ...); DESCRIPTION
xdf_set_conf() sets the configuration (usually one of the field file header) of a xDF file referenced by xdf according to the variable list of arguments. This list is composed of successive couple grouping one variable of type enum xdffield defining the feature to be set and a value whose type depends on the previous field type. The list must finish by XDF_NOF. xdf_get_conf() gets the configuration of the channel referenced by xdf according to the variable list of argument. The variable list is the same list terminated by XDF_NOF as for xdf_set_conf() excepting that the second part of the couple is not that value but a pointer to the value. Both functions process the argument list from left to right. This means that if a particular field request provokes an error, none of the field requests on its right will be processed. The order of processing is also important for field requests that influences the value of other fields (like XDF_F_REC_NSAMPLE or XDF_F_SAMPLING_FREQ). The functions accepts two types of field value. The first one are file configuration field (XDF_F_*) which set different aspects of the general configuration of the file. The second type are the channel configuration fields (XDF_CF_*). When used in xdf_set_conf(), those fields set the default values that will be used for the creation of the next channel (see xdf_add_channel(3)). The list of channel configu- ration fields and their meaning are specified in the documentation of xdf_set_chconf(3). If the file is opened for writing, each field is initialized to sensible or non-informative values in case of optional field or incorrect values in the case of "must be set" field (only XDF_F_REC_NSAMPLE or XDF_F_SAMPLING_FREQ). The default value are specified in squared bracked in the list. Here is the list of file configuration field value. The type of value expected is provided in the parenthesis (the expected type of the value for xdf_set_conf(), or a pointer to this type for xdf_get_conf()). If a list of data formats is specified in curl brackets, it means that the field is supported only in those formats (no list means that all formats support the field): XDF_F_REC_DURATION (double) [1] Specify the duration of one record. The value should be positive. XDF_F_REC_NSAMPLE (int) [0] Specify the number of time points contained in each record. The value should be positive. Setting the number of sample per record modifies the sampling frequency (field XDF_SAMPLING_FREQ). XDF_F_SAMPLING_FREQ (int) [0] Get or set the sampling frequency of the recording. Setting the sampling frequency modifies the number of sample per record (field XDF_F_REC_NSAMPLE). XDF_F_NCHANNEL (int) (get function only) Get the number of channel in the file. XDF_F_NEVTTYPE (int) (get function only) Get the number of different event types. XDF_F_NEVENT (int) (get function only) Get the number of events. XDF_F_FILEFMT (int) (get function only) Get the file format type (one of the value defined by the enumeration xdffiletype other than XDF_ANY) XDF_F_RECTIME (double) [current time] {EDF BDF GDF} Date and time of recording. It is expressed as number of seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). This num- ber is the convertion to double of the value returned by the function time(3) of the standard C library. On file creation, this field is initialized to the current time. XDF_F_SUBJ_DESC (const char*) [""] {EDF BDF GDF} Specify the string describing the subject. XDF_F_SESS_DESC (const char*) [""] {EDF BDF GDF} Specify the string describing the session of recording. XDF_F_ADDICTION (unsigned int) [0] {GDF} XDF_F_BIRTHDAY (double) [0] {GDF} Birthday of the patient using the same format as specified for field XDF_F_RECTIME. XDF_F_HEIGHT (double) [0] {GDF} Height of the subject in centimeters. XDF_F_WEIGHT (double) [0] {GDF} Weight of the subject in kilograms. XDF_F_GENDER (unsigned int) [0] {GDF} Sex of the subject. Use 1 for male, 2 for female and 0 if unknown. XDF_F_HANDNESS (unsigned int) [0] {GDF} Handness of the subject. Use 0 if unknown, 1 if right, 2 if left and 3 if ambidextrious. XDF_F_VISUAL_IMP (unsigned int) [0] {GDF} Visual impairment. Use 0 if unknown, 1 if no impairment, 2 if impaired and 3 if impaired but corrected. XDF_F_HEART_IMP (unsigned int) [0] {GDF} Heart impairment. Use 0 if unknown, 1 if no impairment, 2 if impaired and 3 if the subject wear a pacemaker. XDF_F_LOCATION (double[3]) [0,0,0] {GDF} Location of the recording. The first 2 component specify the latitude and longitude in degrees, the third specifies the altitude in meters. XDF_F_ICD_CLASS (char[6]) [0x000000000000] {GDF} Patient classification according to the International Statistical Classification of Diseases and Related Health Problems (ICD). XDF_F_HEADSIZE (double[3]) [0,0,0] {GDF} Size of the subject's head (circumference, distance nasion - inion, left to right mastoid) expressed in millimeters. XDF_F_REF_POS (double[3]) [0,0,0] {GDF} X, Y, Z coordinates of the reference electrode. XDF_F_GND_POS (double[3]) [0,0,0] {GDF} X, Y, Z coordinates of the ground electrode. RETURN VALUE
The two functions returns 0 in case of success. Otherwise -1 is returned and errno is set appropriately. ERROR
EINVAL xdf is NULL or field is not a proper value of the enumeration xdffield accepted by the function (for example XDF_F_NCHANNEL and xdf_set_conf() ) EPERM The request submitted to xdf_set_conf() is not allowed for this type of xDF file or is not supported with the mode XDF_READ. EXAMPLES
Example of usage of xdf_set_conf() and xdf_get_conf(): /* Assume xdfr and xdfw reference 2 XDF files opened respectively * for reading and for writing */ const char *subjstr, *sessstr; xdf_get_conf(xdfr, XDF_F_SUBJ_DESC, &subjstr, XDF_F_SESS_DESC, &sessstr, XDF_NOF); printf("subject: %s recording: %s ", subjstr, sessstr); xdf_set_conf(xdfw, XDF_F_SUBJ_DESC, subjstr, XDF_F_SESS_DESC, sessstr, XDF_NOF); SEE ALSO
xdf_copy_conf(3), xdf_set_chconf(3), xdf_add_channel(3) EPFL
2010 XDF_SET_CONF(3)
All times are GMT -4. The time now is 02:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy