![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| delete two patterns and remove one pattern | ppat7046 | Shell Programming and Scripting | 7 | 04-08-2009 10:19 AM |
| Delete lines between two patterns without deleting the second pattern | Ilja | Shell Programming and Scripting | 1 | 11-14-2008 09:53 AM |
| Grep All lines between 2 different patterns | gurpreet470 | Shell Programming and Scripting | 2 | 11-07-2008 04:45 PM |
| Getting the lines between last occurrence of two patterns | rvz | Shell Programming and Scripting | 8 | 08-08-2008 06:32 PM |
| How to get lines in between Patterns? | racbern | Shell Programming and Scripting | 11 | 04-23-2008 08:28 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|