Sponsored Content
Top Forums Shell Programming and Scripting delete lines between patterns Post 302320681 by shamushamu on Thursday 28th of May 2009 02:52:43 PM
Old 05-28-2009
Ghostdog, Im not sure where the More Unix/Linux Forum is because I couldn't find it in this forum list.

I was able to get a code from this forum and apply it to what I'm doing. It's not exact but it's close.


code
-----
Code:
#!/bin/bash
function drcext
{
# Extract one line above and two lines below a pattern
awk '/[1-9] [1-9] /{ before-=1;after=2; next }
after { after--;next }
{ store[++before]=$0}
END {
for(i=1;i<=before;i++) {
print store[i]
}
}' b > c
diff b c > d
sed -i 's/[0-9]*,[0-9]*[a-z]*[0-9]*/----------------------------------------------------------------/g' d
sed -i 's/< //g' d
# Add a variable content to the beginning of the file
rulepath=`grep Rule d`
sed -i '/Rule/d' d
sed "1i $rulepath" < d > e
}
drcext


This is my input file:

inputfile b
---------
Code:
die1 1000

WARN_1
0 0 2 May 4 16:20:21 2009 
Rule File Pathname: /coms
Rule File Pathname: /home/la/_tij4_drc_
TEOS_CH minimum spacing to VIA_1 is 10.0u, must not overlap
23_K
1 1 2 May 4 16:24:00 2009 
Rule File Pathname: /home/la/_tij4_drc_
TEOS_CH must be enclosed by Metal_3 10um min
p 1 4
CN tmplt c 1 0 0 1 0 0
-1512633 -8706882
-1507100 -8715212
-1507100 -8668836
-1512633 -8677166

Rule File Pathname: /home/la/_tij4_drc_
SU8_chm to Bond Pad min space is 10 um 
45_D2
20 20 2 May 4 16:30:03 2009 
Rule File Pathname: /home/la/_tij4_drc_
SU8_chm to Bond Pad at the end of a row min space is 100 um
e 1 2
CN die1 c 1 0 0 1 0 0
-1366000 -9000000 -1366000 -8991408
-1461658 -9029146 -1457396 -9031988
e 2 2
-1366000 -9000000 -1366000 -8981773
-1457396 -9031988 -1450898 -9034615
e 3 2
-1366000 -8804227 -1366000 -8800000

Rule File Pathname: /home/la/_tij4_drc_
Primer must be enclosed by SU8_prm
AT_1
2 2 2 May 4 16:30:20 2009 
Rule File Pathname: /home/la/_tij4_drc_
target must be covered by (drawn) dso
p 1 36
CN target_bondalign c 1 0 0 1 -1676600 7170000
-24000 0
-23635 -4168

Rule File Pathname: /home/la/_tij4_drc_
SU8_prm must overlap dso over gld_tgt by 3um min
AT_5
2 2 2 May 4 16:30:20 2009 
Rule File Pathname: /home/la/_tij4_drc_
SU8_prm/chm/nzl not allowed over gld_tgt
p 1 36
CN target_bondalign c 1 0 0 1 -1676600 7170000
-24000 0
-23635 -4168
-22553 -8208
-20785 -12000
-18385 -15427

Rule File Pathname: /home/la/_tij4_drc_
contact not allowed in stitch zone
su8_14_26A
55 55 2 May 4 16:30:30 2009 
Rule File Pathname: /home/la/_tij4_drc_
NOZZLE minimum width is 10um (for 14um thick material)
p 1 114
CN resistor_array c 1 0 0 1 0 0
-1052100 -7525307
-1052067 -7525796
-1052066 -7525803
-1051974 -7526268


This is my output file:

outputfile e
-----------
Code:
Rule File Pathname: /home/la/_tij4_drc_
----------------------------------------------------------------
23_K
1 1 2 May 4 16:24:00 2009 
TEOS_CH must be enclosed by Metal_3 10um min
----------------------------------------------------------------
AT_1
2 2 2 May 4 16:30:20 2009 
target must be covered by (drawn) dso
----------------------------------------------------------------
AT_5
2 2 2 May 4 16:30:20 2009 
SU8_prm/chm/nzl not allowed over gld_tgt
----------------------------------------------------------------
su8_14_26A
55 55 2 May 4 16:30:30 2009 
NOZZLE minimum width is 10um (for 14um thick material)

I'm not sure why the awk command delete the lines that are found by the search pattern [1-9] [1-9]. The originally posting for this code is for to extract the one line above and two lines below the pattern [1-9] [1-9]. This code is backward. It deletes instead of extract that's why I have to use the diff to get the lines that were delete. Please let me know how to recode it to extract instead of delete.

There is one problem with this code that I dont understand is that I use the pattern [1-9] [1-9] so it shouldn't be extracting the line:

55 55 2 May 4 16:30:30 2009

But that is what I wanted. I also want the line:

20 20 2 May 4 16:30:03 2009

But it didn't get extracted. How do I change the pattern /[1-9] [1-9] /, so that it will find any string; ie; 55 55 2 or 20 20 2? I've tried a different pattern /[1-9]* [1-9]* / or something along that line, but it's not working.

Sorry for the lengthy request but any advise would be greatly appreciated. This is my code:

Last edited by vgersh99; 05-28-2009 at 04:01 PM.. Reason: added code tags
 

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