Removing last two lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing last two lines
# 1  
Old 12-08-2009
Removing last two lines

I have an awk script that replaces ">" with

[CODE]
%
%>

%< SOURCE", ++i
%( PHASE 1", i
[CODE]

I use the following script

Code:
/>/ {
   if ( FNR > 1 ) {
      print "%)"
      print "%>"
   }
   print ""
   print "%< SOURCE", ++i
   print "%( PHASE 1", i
}

This produces

Code:
%< SOURCE 64
%( PHASE 1 64
160 30.9858 30.9858
163 29.8366 29.8366
166 28.631 28.631
169 27.3611 27.3611
172 26.0695 26.0695
175 24.6813 24.6813
178 23.1547 23.1547
181 21.4705 21.4705
184 19.4407 19.4407
187 16.9838 16.9838
190 13.9672 13.9672
193 10.3105 10.3105
196 5.92347 5.92347
199 0 0
%)
%>

%< SOURCE 65
%( PHASE 1 65


Hence at the end I end up with

Code:
%< SOURCE 65
%( PHASE 1 65

which I want to remove. Any ideas on how can I do this please?

---------- Post updated at 07:14 AM ---------- Previous update was at 06:52 AM ----------

Is it possible to do it in awk and include it in the awk script?
# 2  
Old 12-08-2009
Not sure I understand.

Can you not just say:

Code:
/>/ {
   if ( FNR > 1 ) {
      print "%)"
      print "%>"
   } else {
     print "%< SOURCE", ++i
     print "%( PHASE 1", i
  }
}

# 3  
Old 12-08-2009
No because this will remove

Code:
%< SOURCE ++i
%( PHASE 1 i

at the beginning of each block. The last one is ok though
Code:
%)
%>
157 30.9858 30.9858
160 29.8366 29.8366
163 28.631 28.631
166 27.3611 27.3611
169 26.0695 26.0695
172 24.6813 24.6813
175 23.1547 23.1547
178 21.4705 21.4705
181 19.4407 19.4407
184 16.9838 16.9838
187 13.9672 13.9672
190 10.3105 10.3105
193 5.92347 5.92347
196 0 0
199 5.92347 5.92347
%)
%>
160 30.9858 30.9858
163 29.8366 29.8366
166 28.631 28.631
169 27.3611 27.3611
172 26.0695 26.0695
175 24.6813 24.6813
178 23.1547 23.1547
181 21.4705 21.4705
184 19.4407 19.4407
187 16.9838 16.9838
190 13.9672 13.9672
193 10.3105 10.3105
196 5.92347 5.92347
199 0 0
%)
%>

However I should get

Code:
%< SOURCE 63
%( PHASE 1 63
157 30.9858 30.9858
160 29.8366 29.8366
163 28.631 28.631
166 27.3611 27.3611
169 26.0695 26.0695
172 24.6813 24.6813
175 23.1547 23.1547
178 21.4705 21.4705
181 19.4407 19.4407
184 16.9838 16.9838
187 13.9672 13.9672
190 10.3105 10.3105
193 5.92347 5.92347
196 0 0
199 5.92347 5.92347
%)
%>

%< SOURCE 64
%( PHASE 1 64
160 30.9858 30.9858
163 29.8366 29.8366
166 28.631 28.631
169 27.3611 27.3611
172 26.0695 26.0695
175 24.6813 24.6813
178 23.1547 23.1547
181 21.4705 21.4705
184 19.4407 19.4407
187 16.9838 16.9838
190 13.9672 13.9672
193 10.3105 10.3105
196 5.92347 5.92347
199 0 0
%)
%>

# 4  
Old 12-08-2009
Can you post a sample of your input (at least two blocks)?
# 5  
Old 12-08-2009
... and your awk script Smilie
# 6  
Old 12-08-2009
Two blocks of the input file

Code:
>
10 0 
13 5.92346 
16 10.3106 
19 13.9672 
22 16.9838 
25 19.4407 
28 21.4705 
31 23.1547 
34 24.6813 
37 26.0695 
40 27.3611 
43 28.631 
46 29.8366 
49 30.9858 
52 32.0934 
55 33.1458 
58 34.1637 
61 35.1297 
64 36.0253 
67 36.9248 
70 37.8001 
73 38.6296 
76 39.4503 
79 40.2424 
82 40.997 
85 41.7681 
88 42.5001 
91 43.2316 
94 43.9289 
97 44.6221 
100 45.3015 
103 45.9617 
106 46.6138 
109 47.2457 
112 47.8904 
115 48.5016 
118 49.1305 
121 49.7498 
124 50.3272 
127 50.8841 
130 51.472 
133 52.0619 
136 52.6079 
139 53.1586 
142 53.7149 
145 54.2602 
148 54.7771 
151 55.3154 
154 55.8316 
157 56.366 
160 56.8704 
163 57.358 
166 57.8577 
169 58.338 
172 58.8308 
175 59.308 
178 59.7918 
181 60.2547 
184 60.7199 
187 61.1781 
190 61.643 
193 62.1091 
196 62.5579 
199 62.9957 
>
10 5.92346 
13 0 
16 5.92346 
19 10.3106 
22 13.9672 
25 16.9838 
28 19.4407 
31 21.4705 
34 23.1547 
37 24.6813 
40 26.0695 
43 27.3611 
46 28.631 
49 29.8366 
52 30.9858 
55 32.0934 
58 33.1458 
61 34.1637 
64 35.1297 
67 36.0253 
70 36.9248 
73 37.8001 
76 38.6295 
79 39.4503 
82 40.2424 
85 40.9969 
88 41.7681 
91 42.5001 
94 43.2316 
97 43.9289 
100 44.6221 
103 45.3016 
106 45.9617 
109 46.6137 
112 47.2457 
115 47.8904 
118 48.5016 
121 49.1304 
124 49.7498 
127 50.3272 
130 50.8841 
133 51.472 
136 52.0619 
139 52.608 
142 53.1586 
145 53.7149 
148 54.2603 
151 54.7771 
154 55.3154 
157 55.8315 
160 56.3661 
163 56.8704 
166 57.358 
169 57.8597 
172 58.3415 
175 58.8302 
178 59.3081 
181 59.7919 
184 60.2545 
187 60.7185 
190 61.1985 
193 61.6302 
196 62.1146 
199 62.5397 
>

# 7  
Old 12-08-2009
Similar to what you had originally:
Code:
awk '
  />/ { if ( NR > 1) {
          print "%)"
          print "%>"
          print ""
        }

        P = 1
        next
  }

  P {
     print "%< SOURCE", ++i
     print "%( PHASE 1", i
     P = 0
  }
  1
'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

2. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

3. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

4. Shell Programming and Scripting

Removing lines from a file

Hi, I have a linux server that was hacked and I have a bunch of files that sporadically contain the following lines through out the file: <?php eval(base64_decode("Xxxxxxxxxxxxxx/xxxxxxxx")); I did't put the exact lines of the file in this post. The "Xxxx" are random letters/numbers.... (8 Replies)
Discussion started by: nck
8 Replies

5. Shell Programming and Scripting

Removing lines with condition

Hello guys, I need help with a script for removing lines that does not satisfy a condition. For example if a file has these lines: aaaa bbbb cccc aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll aaaa bbbb cccc jjjj kkkk lllll dddd eeee ffff dddd eeee ffff Then I want... (4 Replies)
Discussion started by: jaysean
4 Replies

6. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

7. Shell Programming and Scripting

Removing lines having #

I have a script which goes to different directories and gives the values of all the input parameters, Something as follows cd /opt grep script-filter = yes *.conf grep user-and-group-in-same-suffix = yes *.conf grep worker-threads = 300 *.conf grep failover-auth = *.conf grep... (9 Replies)
Discussion started by: openspark
9 Replies

8. Shell Programming and Scripting

Removing lines with sed

Here is some code output that I have: architecture ppc cputype CPU_TYPE_POWERPC cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 4096 size 184464 align 2^12 (4096) architecture ppc64 cputype CPU_TYPE_POWERPC64 cpusubtype CPU_SUBTYPE_POWERPC_ALL offset 192512 ... (5 Replies)
Discussion started by: pcwiz
5 Replies

9. Shell Programming and Scripting

Removing Blank Lines

Hi i have the below lines from a file 7538 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036 PRGRP450800PERSONAL SOAP AND BATH ADDITIV 7036... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

10. Shell Programming and Scripting

Removing lines within a file

Hi There, I've written a script that processes a data file on our system. Basically the script reads a post code from a list file, looks in the data file for the first occurrence (using grep) and reads the line number. It then tails the data file, with the line number just read, and outputs to a... (3 Replies)
Discussion started by: tookers
3 Replies
Login or Register to Ask a Question