Sponsored Content
Top Forums UNIX for Dummies Questions & Answers search one row and print next 9 rows Post 302435468 by Gery on Wednesday 7th of July 2010 12:15:32 PM
Old 07-07-2010
search one row and print next 9 rows

Hi,

I'd like your support on this, my file looks like this:

Code:
25 50 200 10 0 1
10 6 12 17 26 24 30 319 10 -0.83 3.31 270.646 12.48
-163.04 30.38 0 0 0 -2.88 0.64 16.06 34.4 33.08 34.4 33.08
34.06 20.48 6.22 -33.39 33.96
-33.5840381 -71.6177759 -163.26 25.59 34.1
-28.8 -5.6 -9.9 0 0 0 0 2.2 26.2
200 cm GGA dB 0.45 0.077
2.2 12.09 84.69 12 1.1 -2.5 -3.6 69.5 71.1 73.3 78.4 30 -0.08
3.2 13.54 68.95 12.6 4.9 -1.3 12.6 71.7 72.3 77.2 77.5 80 -0.81
4.2 18.47 91.96 18.5 -0.6 -3 13.8 73 73.5 76.7 77.5 80 0.71
5.2 10.53 330.77 -5.1 9.2 2.1 2 71.2 73.6 72.5 75.8 80 0.2
6.2 14.93 13.13 3.4 14.5 3.2 -0.2 74.2 73.4 74.7 74 90 0.4
7.2 27.97 14.42 7 27.1 5.3 6.2 74.5 75.6 74 74.5 90 0.14
8.2 10.09 357.77 -0.4 10.1 4.4 6.9 73.8 74.2 73.9 73.7 90 -0.48
9.2 17.73 36.61 10.6 14.2 -0.3 -5.8 73.5 73.4 72.5 76.6 80 -1.37
10.2 23.17 14.64 5.9 22.4 6.2 3.2 74.9 72.3 75.2 76.5 90 -1.81
11.2 17.77 46.43 12.9 12.2 4.7 -8.4 70.1 75.2 77 73.1 70 -0.08
12.2 6.85 72.92 6.6 2 9.8 3.7 69.1 78.4 79.3 72.6 70 0.4
13.2 8.84 274.45 -8.8 0.7 5.9 -3.4 69.4 78.1 78.9 71.5 90 -0.36
14.2 5.11 46.7 3.7 3.5 5.6 10.7 68.3 76.6 75.7 70.7 90 -0.37
15.2 10.09 78.34 9.9 2 3.7 6.5 69 73.8 74.4 71.3 100 -0.65
16.2 1.33 126.66 1.1 -0.8 9.4 -5.3 71.1 73 75.6 73.6 90 0.19
17.2 10.83 195.46 -2.9 -10.4 8.1 -3.2 69.8 73.6 76.1 74.1 90 0.18
18.2 11.02 21.98 4.1 10.2 0.6 -12.4 68.4 72.4 75.5 75.6 80 0.1
19.2 3.99 216.43 -2.4 -3.2 0.6 1.7 69.2 72.8 73.9 75.9 80 1.5
20.2 21 198.44 -6.6 -19.9 1.6 5.2 70.1 73.7 72.4 76.7 80 1.28
21.2 0.28 272.37 -0.3 0 -4.9 2.4 69.7 72.1 72.6 77.1 80 0.82
22.2 9.13 31.22 4.7 7.8 3 -6.3 69 72.9 72.5 78.2 90 0.51
23.2 18.67 123.04 15.6 -10.2 13.5 13.5 69.2 75.2 72.4 79.2 60 0.17
24.2 12 230.6 -9.3 -7.6 8.5 -1.5 69.5 76.2 73.3 79.4 80 0.17
25.2 10.46 162.83 3.1 -10 10 -3.7 68.7 73.6 74.2 77.9 80 2.83
26.2 10.39 100.51 10.2 -1.9 4 20.5 68.9 73.5 76 77.1 70 1.1
27.2 19.43 191.21 -3.8 -19.1 33.9 15 68.8 76.1 76.9 77.9 30 2147483647
28.2 18.52 183.91 -1.3 -18.5 21.7 0.4 70.4 77.2 79.4 76.5 40 2147483647
29.2 14.28 293.12 -13.1 5.6 19.1 -6.5 73.1 79.5 78.5 75.6 40 2147483647
30.2 -32768 -32768 -32768 -32768 -32768 -32768 76.2 91.6 81.1 81.6 0 2147483647
31.2 -32768 -32768 -32768 -32768 -32768 -32768 84 108.7 88.8 96.8 0 2147483647
32.2 -32768 -32768 -32768 -32768 -32768 -32768 98.2 113.2 102.9 115.2 0 2147483647
33.2 -32768 -32768 -32768 -32768 -32768 -32768 110.7 255 109.6 122 0 2147483647
34.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
35.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
36.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
37.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
38.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
39.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
40.2 -32768 -32768 -32768 -32768 -32768 -32768 255 255 255 255 0 2147483647
...

I need to search the row with the pattern -33.5840381 -71.6177759 and then avoid the next two rows, and then print the next 9 rows (in read above). To find the pattern I tried:
Code:
grep '[-][0-9]\{2\}.[0-9]\{7\}' file.txt

but it just print the lines with that pattern. Two avoid the two rows I tried:

Code:
awk 'NR==6 || NR==7 {print}' file.txt

but I know the current position of them in the example (this is one second of my data). However, my file is 30000 rows with a similar structure.

To print the next 9 rows, I tried this:
Code:
awk 'NR>4 && NR<17' file.txt

but like above, I know the current position of them.

I'd greatly appreciate your support.

Regards.

Last edited by vgersh99; 07-07-2010 at 01:46 PM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Concatenate 2 rows into 1 row

I need to search a file for two values (valueA & valueB). ValueA will be on a different row than valueB, and concatenate the two together on the same row of my output. Example: search input file for strings "node" and "OS", combine the two results into one row input node A text text OS... (4 Replies)
Discussion started by: indianadoug
4 Replies

2. Shell Programming and Scripting

Insert rows with computations of next row

Hello folks, I have data collected in every 3 hours. But, I would like to expand this to 1 hour interval by equally dividing with next row. For example, I want to keep the first value 1987-01-01-00z 2.0, but following all record should be re-written as follow. 1987-01-01-03z 5.0 becomes... (11 Replies)
Discussion started by: Jae
11 Replies

3. UNIX for Advanced & Expert Users

convert rows to single row

Hi I want to convert multiple rows ro single row ,I have tried with below one but I am not getting what I am expecting.Please any idea a.txt conn1=stg conn2=dev path=\xxx\a1.txt fre=a conn1=stg conn2=dev path=\xxx\a2.txt freq=a awk '/a/{ORS=" "}{print}END{print "\n"}'... (5 Replies)
Discussion started by: akil
5 Replies

4. UNIX for Advanced & Expert Users

Converting rows to a single row

Hi all I have a file as below : Development System User Production i want to convert the file to below format: "Development","System","User","Production" Is it possible with UNIX ? if so can you please give me some direction on it ? Thanks, Satya Use code tags please, ty. (10 Replies)
Discussion started by: satyaranjon
10 Replies

5. Shell Programming and Scripting

complicated row to rows conversion

I have a file containing rows with the following format. Field1|Field2|Field3|data1:data data2:data data3:"dataA:data dataB:data" data4:data:data (and so on) I need to format the above row into multiple rows that look like this: Field1|Field2|Field3|data1|data ... (2 Replies)
Discussion started by: newreverie
2 Replies

6. Shell Programming and Scripting

Print various rows in one row

I have this in a file 11.22.33.44 yyyyyyuser With awk/sed, I need this to be output as follows alias server.domain.com='ssh yyyyyyuser@11.22.33.44' (4 Replies)
Discussion started by: anil510
4 Replies

7. Shell Programming and Scripting

Get row number from file1 and print that row of file2

Hi. How can we print those rows of file2 which are mentioned in file1. first character of file1 is a row number.. for eg file1 1:abc 3:ghi 6:pqr file2 a abc b def c ghi d jkl e mno f pqr ... (6 Replies)
Discussion started by: Abhiraj Singh
6 Replies

8. Shell Programming and Scripting

Search row by row from one file to another file if match is found print few colums of file 2

this is the requirement list.txt table1 table2 table3 testfile.txt name#place#data#select * from table1 name2#place2#data2#select * from table 10 innerjoin table3 name2#place2#data2#select * from table 10 output name place table1 name2 place table3 i tried using awk (7 Replies)
Discussion started by: vamsekumar
7 Replies

9. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

10. 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
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy