Sponsored Content
Top Forums Shell Programming and Scripting delete lines between patterns Post 302319998 by shamushamu on Tuesday 26th of May 2009 08:33:43 PM
Old 05-26-2009
delete lines between patterns

Hi, I've searched in this forum all day long but was not able to find enough codes to help me do a task. The only code that I can come up with is this:

sed '/[0-9] [0-9] /,/[0-9] [0-9] /{//p;d;}' inputfile > outputfile

I would like to sed/awk/grep a file for two patterns and then delete the lines between those patterns. Please see the inputfile below. This is just a small portion of a lengthy file. Everything in bold should be deleted.

In this case, I would like to search for the first pattern [0 0 2] and the last pattern [2433 2433 2], then delete every line between these patterns but keeping the line [ANT_2] above the line [2433 2433 2]. Similarly, I would like to search for the first pattern [0 0 4] and the last pattern [1 1 2], then delete every line between these patterns but keeping the line [ANT_6] above the line [1 1 2]. The number of lines between these pattens can vary. The only thing that I can see that is constant is the [0 0 ].

Any help or suggestion would be greatly appreciated.

inputfile
--------
ANT_1
0 0 2 Jan 14 10:11:44 2009
Rule File Pathname: /home/la/_drc_
ply to gate area ratio > 500
ANT_2
2433 2433 2 Jan 14 10:13:46 2009
Rule File Pathname: /home/la/_drc_
mt1 to gate area ratio > 40
p 1 44
-2109300 -10645700
-2095600 -10645700
-2095600 -10649700
-2088500 -10649700
-2088500 -10655700
-2071900 -10655700
ANT_3
0 0 2 Jan 14 10:13:59 2009
Rule File Pathname: /home/la/_drc_
mt2 diff gate inputs.
ANT_4
0 0 2 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.

ANT_5
0 0 4 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.
ANT_6
1 1 2 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.
NET_AREA_RATIO_RDBS
0 0 3 Jan 14 10:14:01 2009
ANT2.OUT
ANT3.OUT
ANT4.OUT


Desired outputfile
----------------
ANT_2
2433 2433 2 Jan 14 10:13:46 2009
Rule File Pathname: /home/la/_drc_
mt1 to gate area ratio > 40
p 1 44
-2109300 -10645700
-2095600 -10645700
-2095600 -10649700
-2088500 -10649700
-2088500 -10655700
-2071900 -10655700
ANT_6
1 1 2 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete lines between two patterns without deleting the second pattern

I want to delete lines like this sed '/FROM_HERE/,/TO_HERE/d' but I would like to *not* delete the second match, i.e. the TO_HERE line. How can I achieve this? Thank you! (1 Reply)
Discussion started by: Ilja
1 Replies

2. Shell Programming and Scripting

delete two patterns and remove one pattern

Friends, I have .txt file with following format. START ABC|Prashant1|Patel1 ABC|Prashant2|Patel2 ABC|Prashant1|Patel1 ABC|Prashant2|Patel2 END I would like to do: 1) Delete line with START 2) Delete line with END 3) Remove ABC| 4) Delete duplicate records The following command... (7 Replies)
Discussion started by: ppat7046
7 Replies

3. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies

4. Shell Programming and Scripting

Delete line breaks and extra spaces between patterns

Hi, if in between strings "<section" and "</section>" across multiple lines there occurs the string "ole-present", delete all line breaks and replace any tabs or multiple spaces with a single space. Looking for an AWK or SED solution. Thank you. <section ... status = "ole-present" ...... (2 Replies)
Discussion started by: pioavi
2 Replies

5. Shell Programming and Scripting

Match paragraph between two patterns, delete the duplicate paragraphs

Hello all I have a file my DNS server where there are duplicate paragrapsh like below. How can I remove the duplicate paragraph so that only one paragraph remains. BEGIN; replace into domains (name,type) values ('225.168.192.in-addr.arpa','MASTER'); replace into records (domain_id,... (2 Replies)
Discussion started by: sb245
2 Replies

6. Shell Programming and Scripting

Delete lines and the first pattern between 2 matched patterns

Hi, i need help to delete all the lines between 2 matched patterns and the first pattern must be deleted too. sample as follows: inputfile.txt >kump_1 ........................... ........................... >start_0124 dgfhghgfh fgfdgfh fdgfdh >kump_2 ............................. (7 Replies)
Discussion started by: redse171
7 Replies

7. Shell Programming and Scripting

Delete values between 2 patterns

Hi, How can i delete values between 2 patterns like below:- input.txt 192.1.1.2.22 blablabala 23.1.A.1.2 blablabalbl 5.4.1.1.12 blablaba i need to delete all values between starting from "." no 3 and second column. the output should be: 192.1.1 blablabala... (15 Replies)
Discussion started by: redse171
15 Replies

8. Shell Programming and Scripting

Delete patterns matching

Delete patterns matching OS version: RHEL 7.3 Shell : Bash I have a file like below (pattern.txt). I need to delete all lines starting with the following words (words separated by comma below) and ) character. LOGGING, NOCOMPRESS, TABLESPACE , PCTFREE, INITRANS, MAXTRANS, STORAGE,... (3 Replies)
Discussion started by: John K
3 Replies

9. 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

10. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies
File::Find::Object::Rule::Extending(3pm)		User Contributed Perl Documentation		  File::Find::Object::Rule::Extending(3pm)

NAME
File::Find::Object::Rule::Extending - the mini-guide to extending File::Find::Object::Rule SYNOPSIS
package File::Find::Object::Rule::Random; use strict; use warnings; # take useful things from File::Find::Object::Rule use base 'File::Find::Object::Rule'; # and force our crack into the main namespace sub File::Find::Object::Rule::random () { my $self = shift()->_force_object; $self->exec( sub { rand > 0.5 } ); } 1; DESCRIPTION
File::Find::Object::Rule inherits File::Find::Rule's extensibility. It is now possibile to extend it, using the following conventions. Declare your package package File::Find::Object::Rule::Random; use strict; use warnings; Inherit methods from File::Find::Object::Rule # take useful things from File::Find::Object::Rule use base 'File::Find::Object::Rule'; Force your madness into the main package # and force our crack into the main namespace sub File::Find::Object::Rule::random () { my $self = shift()->_force_object; $self->exec( sub { rand > 0.5 } ); } Yes, we're being very cavalier here and defining things into the main File::Find::Object::Rule namespace. This is due to lack of imaginiation on my part - I simply can't find a way for the functional and oo interface to work without doing this or some kind of inheritance, and inheritance stops you using two File::Find::Object::Rule::Foo modules together. For this reason try and pick distinct names for your extensions. If this becomes a problem then I may institute a semi-official registry of taken names. Taking no arguments. Note the null prototype on random. This is a cheat for the procedural interface to know that your sub takes no arguments, and so allows this to happen: find( random => in => '.' ); If you hadn't declared "random" with a null prototype it would have consumed "in" as a parameter to it, then got all confused as it doesn't know about a '.' rule. NOTES ABOUT THE CALLBACK
The callback can access the File::Find::Object::Result using "$self->finder->item_obj()". AUTHOR
Richard Clamp <richardc@unixbeard.net> COPYRIGHT
Copyright (C) 2002 Richard Clamp. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
File::Find::Object::Rule File::Find::::Rule::MMagic was the first extension module for File::Find::Rule, so maybe check that out. perl v5.14.2 2012-05-05 File::Find::Object::Rule::Extending(3pm)
All times are GMT -4. The time now is 04:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy