Extract row grater than 3 from previous value of a field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract row grater than 3 from previous value of a field
# 1  
Old 08-26-2016
Extract row grater than 3 from previous value of a field

Hi,

I am trying to extract data where first field unique value and 4th field of next row is grater than first row 4th field.

input data is a below:

Code:
 7035719974,20-jul-2016 07:42:51,07:42:51,074251,1
7035719974,20-jul-2016 07:43:57,07:43:57,074357,2
7399206761,20-jul-2016 04:16:30,04:16:30,041630,1
7399206761,20-jul-2016 04:16:30,04:16:30,041630,2
7662002928,20-jul-2016 08:50:15,08:50:15,085015,1
7662002928,20-jul-2016 08:52:31,08:52:31,085231,2
7662004970,20-jul-2016 08:30:16,08:30:16,083016,1
7662004970,20-jul-2016 08:33:55,08:33:55,083355,2
7662010253,20-jul-2016 07:21:35,07:21:35,072135,1
7662010253,20-jul-2016 07:23:19,07:23:19,072319,2
7662011525,20-jul-2016 10:16:36,10:16:36,101636,1
7662011525,20-jul-2016 10:16:37,10:16:37,101637,2
7662012030,20-jul-2016 01:00:00,01:00:00,010000,1
7662012030,20-jul-2016 09:41:39,09:41:39,094139,2
7662020365,20-jul-2016 09:51:55,09:51:55,095155,1
7662020365,20-jul-2016 10:51:46,10:51:46,105146,2
7662021790,20-jul-2016 03:50:00,03:50:00,035000,1
7662021790,20-jul-2016 03:52:28,03:52:28,035228,2
7662023663,20-jul-2016 06:00:40,06:00:40,060040,1
7662023663,20-jul-2016 06:00:40,06:00:40,060040,2

Desired output should be as below:

Code:
 7035719974,20-jul-2016 07:42:51,07:42:51,074251,1
7035719974,20-jul-2016 07:43:57,07:43:57,074357,2

I am unable to extract the same however I had inserted the fifth field by identifying the first column duplicate and the fifth column contains 1 and 2 values for every duplicated rows based on first column.

Last edited by RudiC; 08-26-2016 at 09:04 AM..
# 2  
Old 08-26-2016
Any attempts/ideas/thoughts from your side?

And, why just those two lines in the output? There's other lines that fulfill your requirement as well...

Last edited by RudiC; 08-26-2016 at 09:16 AM..
# 3  
Old 08-26-2016
Howsowever, try:
Code:
awk '{getline T; split (T, TMP); if ($4 < TMP[4]) {print; print T}}' FS=, file4
7035719974,20-jul-2016 07:42:51,07:42:51,074251
7035719974,20-jul-2016 07:43:57,07:43:57,074357
7662002928,20-jul-2016 08:50:15,08:50:15,085015
7662002928,20-jul-2016 08:52:31,08:52:31,085231
7662004970,20-jul-2016 08:30:16,08:30:16,083016
7662004970,20-jul-2016 08:33:55,08:33:55,083355
7662010253,20-jul-2016 07:21:35,07:21:35,072135
7662010253,20-jul-2016 07:23:19,07:23:19,072319
7662011525,20-jul-2016 10:16:36,10:16:36,101636
7662011525,20-jul-2016 10:16:37,10:16:37,101637
7662012030,20-jul-2016 01:00:00,01:00:00,010000
7662012030,20-jul-2016 09:41:39,09:41:39,094139
7662020365,20-jul-2016 09:51:55,09:51:55,095155
7662020365,20-jul-2016 10:51:46,10:51:46,105146
7662021790,20-jul-2016 03:50:00,03:50:00,035000
7662021790,20-jul-2016 03:52:28,03:52:28,035228

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Analyzing last 2 fields of 1 row and 3rd field of next row

I have the following script that will average the last two fields of each row, but im not sure how to include the 3rd field of the following row. An example of the analysis that I need to perform from the input - (66.61+58.01+54.16)/3 awk '{sum=cnt=0; for (i=13;i<=NF;i++) { sum+=$i; cnt++... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

2. Shell Programming and Scripting

Fill column from previous row

Hi, I have the following content in file ABBR DESC COL3 COL4 COL5 COL6 AAA text desc aaa text text text text text text text text text text text text BBB text desc bbb text text text text text text text text CCC ... (10 Replies)
Discussion started by: bobbygsk
10 Replies

3. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

4. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

5. Shell Programming and Scripting

Insert row without deleting previous data using sed

Hello, I want to add a new row to a file to insert data without deleting the previous data there. Example: file a b c d Output a b newtext c (6 Replies)
Discussion started by: joseamck
6 Replies

6. Shell Programming and Scripting

Print a field from the previous line

plz help me!! I have this file , 3408 5600 3796 6035 4200 6285 4676 0 40 1554 200 1998 652 2451 864 2728 1200 0 I want it like if $2==0,replace it with field from the previous line+500 say here the o/p would be like 3408 5600 3796 6035 4200 6285... (16 Replies)
Discussion started by: Indra2011
16 Replies

7. Shell Programming and Scripting

How to extract previous value

Hi All, I am just trying to write a small script which will take the following output as input, and then search for the 'State' value which is not equal to 0x0000, and then will give me output of respective 'Name'. Name = SYSPACE State ... (10 Replies)
Discussion started by: NARESH1302
10 Replies

8. Shell Programming and Scripting

remove row if string is same as previous row

I have data like: Blue Apple 6 Red Apple 7 Yellow Apple 8 Green Banana 2 Purple Banana 8 Orange Pear 11 What I want to do is if $2 in a row is the same as $2 in the previous row remove that row. An identical $2 may exist more than one time. So the out file would look like: Blue... (4 Replies)
Discussion started by: dcfargo
4 Replies

9. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

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

10. Shell Programming and Scripting

Value of previous row using awk

I would like to know value for previous row, in addition to current row. How would I will get value for previous row? How can I perform this with awk? (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question