Sponsored Content
Top Forums Shell Programming and Scripting How to capture 2 consecutive rows when a condition is true ? Post 302091752 by Raynon on Thursday 5th of October 2006 03:38:23 AM
Old 10-05-2006
How to capture 2 consecutive rows when a condition is true ?

Hi All,

i have an input below.
As long as "x= 1" , i would want to capture 2 lines using sed or awk
for eg :
0001 x= 1 $---------------------------------..-.--..
0001 tt= 137 171 423 1682 2826 0


Pls help. Thanks in advance.
Note that the number of lines in each block do vary.
For eg:
Below is considered 1 block
0001 ECID= DD7VRGB 10 17 23 3 8
0001 dblz= 23 0 0 1 .
0001 ri_esd= 1824 1824 605 605 605 601.5 603 602
0001 x= 1 $---------------------------------..-.--..
0001 tt= 137 171 423 1682 2826 0


Input:
0001 ECID= DD7VRGB 10 17 23 3 8
0001 dblz= 23 0 0 1 .
0001 ri_esd= 1824 1824 605 605 605 601.5 603 602
0001 x= 1 $---------------------------------..-.--..
0001 tt= 137 171 423 1682 2826 0
0002c ECID= DD7VRGB 15 10 135 3 8
0002c shmooU= 3597 3345 2993 2683
0002c dblz= 24 0 0 1 .
0002c ri_esd= 577 577.5 577 573.5 576 574.5 576
0002c x= 1 $----.----------------------------..-.--..--------
0002c tt= 132 167 423 1670 2708 3842 0
0003 ECID= DD7VRGB 8 11 237 3 9
0003 dblz= 25 0 0 1 .
0003 ri_esd= 566 566 566 562 564.5 563.5
0003 x= 28 H---------------------------------..-.--..--------
0003 tt= 130 165 421 1666 2795 0
0004c ECID= DD7VRGB 10 21 206 2 9
0004c shmooU= 7304 6726 5942 5248
0004c dblz= 26 0 0 1 .
0004c ri_esd= 564 564 564 560 562.5 561.5 563
0004c x= 1 $----.----------------------------..-.--..--------
0004c tt= 134 169 424 1676 2714 3766 0


Desired Output:
0001 x= 1 $---------------------------------..-.--..
0001 tt= 137 171 423 1682 2826 0

0002c x= 1 $----.----------------------------..-.--..--------
0002c tt= 132 167 423 1670 2708 3842 0

0004c x= 1 $----.----------------------------..-.--..--------
0004c tt= 134 169 424 1676 2714 3766 0

Last edited by Raynon; 10-05-2006 at 04:55 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to capture no. of rows updated in update sql in unix db2

hi, i am a new user in unix..and we have unix db2. i want to capture the no. of rows updated by a update db2 sql statement and redirect into a log file. I've seen db2 -m...but not sure how the syntax should be. The update sql that I'm going to run is from a file... Can you please share... (1 Reply)
Discussion started by: j_rymbei
1 Replies

2. Shell Programming and Scripting

remove consecutive duplicate rows

I have some data that looks like, 1 3300665.mol 3300665 5177008 102.093 2 3300665.mol 3300665 5177008 102.093 3 3294015.mol 3294015 5131552 102.114 4 3294015.mol 3294015 5131552 102.114 5 3293734.mol 3293734 5129625 104.152 6 3293734.mol ... (13 Replies)
Discussion started by: LMHmedchem
13 Replies

3. Shell Programming and Scripting

Print merged rows from two files by applying if condition

Hi all, I have list of two kind of files and I want to compare the rows and print the merged data by applying if condition. First kind of file looks like: and second kind of file looks like : I want to print the rows present in second file followed by 3 more columns from first... (6 Replies)
Discussion started by: CAch
6 Replies

4. Shell Programming and Scripting

deleting rows under a certain condition

there are 20 variables and I would like to delete the rows if 13th-20th columns are all NA. Thank you! FID IID aspirpre statihos fibrahos ocholhos arbhos betabhos alphbhos cacbhos diurehos numbcig.x toast1 toast2 toast3 toast4 ischoth1 ischoth2 ischoth3 ischoth4 101 101 1 1 1 1 1 2 1 2... (2 Replies)
Discussion started by: johnkim0806
2 Replies

5. Shell Programming and Scripting

Capture rows for a column in file from delete sql -Oracle

Hi, This may not be the right forum but i am hoping someone knows an answer to this. I have to capture rows for a column that was deleted. How can i do that without having to write a select query? delete from myschema.mytable where currentdatetimestamp > columnDate this should delete 5... (4 Replies)
Discussion started by: jakSun8
4 Replies

6. Shell Programming and Scripting

Convert rows to columns based on condition

I have a file some thing like this: GN Name=YWHAB; RC TISSUE=Keratinocyte; RC TISSUE=Thymus; CC -!- FUNCTION: Adapter protein implicated in the regulation of a large CC spectrum of both general and specialized signaling pathways GN Name=YWHAE; RC TISSUE=Liver; RC ... (13 Replies)
Discussion started by: raj_k
13 Replies

7. Shell Programming and Scripting

Columns to Rows - Transpose - Special Condition

Hi Friends, Hope all is well. I have an input file like this a gene1 10 b gene1 2 c gene2 20 c gene3 10 d gene4 5 e gene5 6 Steps to reach output. 1. Print unique values of column1 as column of the matrix, which will be a b c (5 Replies)
Discussion started by: jacobs.smith
5 Replies

8. Shell Programming and Scripting

Average across rows with a condition

Hi Friends, My input file Gene1 10 20 0 Gene2 5 0 15 Gene3 10 10 10 Gene4 5 0 0 If there is a zero for any gene in any column, I don't want that column to be considered which reduces the denominator value during average. Here is my output Gene1 10 20 0 10 Gene2 5 0 15 10 Gene3... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

9. Shell Programming and Scripting

Compute value from more than three consecutive rows

Hello all, I am working on a file like below: site Date time value1 value2 0023 2014-01-01 00:00 32.0 23.7 0023 2014-01-01 01:00 38.0 29.9 0023 2014-01-01 02:00 85.0 26.6 0023 2014-01-01 03:00 34.0 25.3 0023 2014-01-01 04:00 37.0 23.8 0023 2014-01-01 05:00 80.0 20.3 0023 2014-01-01 06:00... (16 Replies)
Discussion started by: kathy wang
16 Replies

10. Shell Programming and Scripting

awk to capture lines that meet either condition

I am trying to modify and understand an awk written by @Scrutinizer The below awk will filter a list of 30,000 lines in the tab-delimited file. What I am having trouble with is adding a condition to SVTYPE=CNV that will only print that line if CI=,0.95: portion in blue in file is <1.9. The... (2 Replies)
Discussion started by: cmccabe
2 Replies
PX_TIMESTAMP2STRING(3)													    PX_TIMESTAMP2STRING(3)

px_timestamp2string - Converts the timestamp into a string.

SYNOPSIS
string px_timestamp2string (resource $pxdoc, float $value, string $format) DESCRIPTION
Turns a timestamp as it stored in the paradox file into human readable format. Paradox timestamps are the number of miliseconds since 0001-01-02. This function is just for convenience. It can be easily replaced by some math and the calendar functions as demonstrated in the following example. PARAMETERS
o $pxdoc - Resource identifier of the paradox database. o $value - Value as stored in paradox database field of type PX_FIELD_TIME, or PX_FIELD_TIMESTAMP. o $format - String format similar to the format used by date(3). The placeholders support by this function is a subset of those supported by date(3) (Y, y, m, n, d, j, H, h, G, g, i, s, A, a, L). RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Turn a paradox timestamp into a human readable form <?php $px = px_new(); /* make up a date as it could be stored in */ /* a date field of a paradox db. */ /* 700000 days since 1.1.0000. */ $days = 700000; /* Use the calendar functions to print a */ /* human readable format of the date */ echo jdtogregorian($days+1721425)." "; /* Turn it into a timestamp as it stored in a paradox database */ /* Timestamps are stored in miliseconds since 0001-01-02 */ $stamp = $days * 86400.0 * 1000.0; /* Add one hour */ $stamp += 3600000.0; /* The following will output '7/15/1917 01:00:00'. */ echo px_timestamp2string($px, $stamp, "n/d/Y H:i:s")." "; px_delete($px); ?> The above example will output: 7/15/1917 7/15/1917 01:00:00 The Julian day count as passed to jdtogregorian(3) has a different base of 1.1.4714 b.c. and must therefore be calculated by adding 1721425 to the day count used in the paradox file. Turning the day count into a timestamp is easily done by multiplying with 86400000.0 to obtain miliseconds. SEE ALSO
px_date2string(3), jdtogregorian(3). PHP Documentation Group PX_TIMESTAMP2STRING(3)
All times are GMT -4. The time now is 02:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy