delete lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting delete lines
# 1  
Old 10-09-2009
delete lines

Hello,

I've got some huge text files look like below. I've cut a couple blocks from about 67000 blocks in the file. Basically, I would like to pick up the second line of each blocks.

Code:
Grid-ref=   1, 148
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
Grid-ref= 217, 158
 2464 6009 2357 1759  559  824  377  699 1598 2311 2987 3650
 4582 2779 2745 1286 1131  409 1834 2733  961 1305 1798 2571
 4565 3847 2958 3990 2599  266 2266 1725 1317 4604 3376 4089
 3458 4595 4535 2314  792 2538  370 3592  935 2429 1630 2962
 3424 2822 2514 2949 4174  574  423  408 2530 2150 2388 4767
 3729 2396 3915 1863 2792 2427  474  722 1312 1834 1752 2727
 2245 3784 1928 2271 1559  312 1663  243 1539 3064 2498 3418
 3804 2205 4010 2058 2049  170 1404  310  815 1052 2513 3572
 2666 3392 3362 2314 1235   50  623  901  662  996 2572 2237
 3846 3217 3436  865 1044  119 1411  324  889 3580 1558 1954
Grid-ref= 217, 159
 2381 6044 2359 1681  627  777  455  686 1879 2053 3169 3460
 4170 3020 2930 1225 1221  615 1711 2395 1002 1544 1743 2356
 4109 3818 2871 3886 2254  399 1921 1465 1350 4562 3348 3463
 3485 4433 4474 2537  734 2134  380 3049 1035 2363 1443 2728
 3390 2443 2692 2780 3465  524  427  470 2307 1838 2502 4413
 3762 2320 3775 1745 2355 1948  426  688 1165 1924 1726 2680
 2012 3714 1859 2123 1445  370 1456  290 1404 2762 2446 3052
 3546 1969 4162 1977 1772  147 1403  249  833 1224 2308 3447
 2518 3071 3284 2243 1160   36  506  811  627  949 2386 2247
 3928 2964 3049  807 1030  131 1259  366  958 3300 1331 1939

So after manipulating the file, it seems to be like this.

Code:
Grid-ref=   1, 148
 3020 2820 3040 2880 1740 1360  980  990 1410 1770 2580 2630
Grid-ref= 217, 158
 4582 2779 2745 1286 1131  409 1834 2733  961 1305 1798 2571
Grid-ref= 217, 159
 4170 3020 2930 1225 1221  615 1711 2395 1002 1544 1743 2356

I've no clue how to work with a huge text file like this and Excel over Window definitely doesn't work.

Any idea would be much appreciate.

Best wishes,

Last edited by Franklin52; 10-09-2009 at 03:55 AM.. Reason: Please use code tags!
# 2  
Old 10-09-2009
Code:
awk '/^Grid/{print;getline;getline;print}' file

# 3  
Old 10-09-2009
Thank you so much for quick reply, danmero

It does show on the screen, I'm wondering how I can save it. I'm sorry if it's a dummy question.

warm regards,
# 4  
Old 10-09-2009
awk '/^Grid/{print;getline;getline;print}' file > file.new
# 5  
Old 10-09-2009
Hi Danmero, I got it.
I am grateful for your help.
All the best,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete multiple lines between blank lines containing two patterns

Hi all, I'm looking for a way (sed or awk) to delete multiple lines between blank lines containing two patterns ex: user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 16... (3 Replies)
Discussion started by: ce9888
3 Replies

2. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

3. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

4. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

5. Shell Programming and Scripting

need to delete all lines from a group of files except the 1st 2 lines

Hello, I have a group of text files with many lines in each file. I need to delete all the lines in each and only leave 2 lines in each file. (3 Replies)
Discussion started by: script_op2a
3 Replies

6. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

7. Shell Programming and Scripting

sed problem - delete all lines until a match on 2 lines

First of all, I know this can be more eassily done with perl or other scripting languages but, that's not the issue. I need this in sed. (or wander if it's possible ) I got a file (trace file to recreate the control file from oracle for the dba boys) which contains some lines another line... (11 Replies)
Discussion started by: plelie2
11 Replies

8. Shell Programming and Scripting

How to delete lines in a file that have duplicates or derive the lines that aper once

Input: a b b c d d I need: a c I know how to get this (the lines that have duplicates) : b d sort file | uniq -d But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Discussion started by: necroman08
3 Replies

9. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

10. Shell Programming and Scripting

How to delete first 5 lines and last five lines in all text files

Hi I want to delete first five and last five lines in text files without opening the file and also i want to keep the same file name for all the files. Thanks in advance!!! Ragav (10 Replies)
Discussion started by: ragavendran31
10 Replies
Login or Register to Ask a Question