Find pattern a delete previous 5 lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find pattern a delete previous 5 lines
# 1  
Old 01-05-2011
Find pattern a delete previous 5 lines

Hi guys,

i have the follow problem i need to delete 10 row before the pattern and 1 after and the pattern row itself.

file looks like:
Code:
frect 9.8438 25.8681 10.625 25 
        . dynprop  \
              (#  \
                (call fox_execute(__self)))  \
              (FOX_VAR_29  \
                (= *   \
                  (fcolor FOX_VAR_29)))  \
              (o23  \
                (= *   \
                  (call fox_oos(__self))))
        . userdata "FOX_VAR=29^attr=FCOLOR^attrval=6^required=0^var=V_0001:00TZ_1005.ALMSTA^delta=1.000000^conv=BITMASK^type=LONG^num_entries=15^entries=0X440000E0,0X44000020,ALL,25,0X420000E0,0X42000020,ALL,25,0X410000E0,0X41000020,ALL,25,0X404000E0,0X40400020,ALL,25,0X402000E0,0X40200020,ALL,25,0X401000E0,0X40100020,ALL,25,0X400200E0,0X40020020,ALL,25,0X400100E0,0X40010020,ALL,25,0X400000E0,0X40000000,ALL,63,0X440000E0,0X4000020,ALL,17,0X420000E0,0X2000020,ALL,17,0X410000E0,0X1000020,ALL,17,0X400200E0,0X20020,ALL,17,0X400100E0,0X10020,ALL,17,0,0,ALL,24^END_FOXV=  ^aname=NULL^alevel=0^action=EXECUTE^required=0^cmd== P4 V_0001 ; = P5 00TZ_1005 ; = P6 1 ; script /opt/script/MTF/ovlCIN^oos_obj=0023"
        . userword 130
        frect 10.625 25.8681 11.4062 25 
        . dynprop  \
              (#  \
                (call fox_execute(__self)))  \
              (FOX_VAR_30  \
                (= *   \
                  (fcolor FOX_VAR_30)))  \
              (o24  \
                (= *   \
                  (call fox_oos(__self))))
        . userdata "FOX_VAR=30^attr=FCOLOR^attrval=6^required=0^var=V_0001:00TZ_1009.ALMSTA^delta=1.000000^conv=BITMASK^type=LONG^num_entries=15^entries=0X440000E0,0X44000020,ALL,25,0X420000E0,0X42000020,ALL,25,0X410000E0,0X41000020,ALL,25,0X404000E0,0X40400020,ALL,25,0X402000E0,0X40200020,ALL,25,0X401000E0,0X40100020,ALL,25,0X400200E0,0X40020020,ALL,25,0X400100E0,0X40010020,ALL,25,0X400000E0,0X40000000,ALL,63,0X440000E0,0X4000020,ALL,17,0X420000E0,0X2000020,ALL,17,0X410000E0,0X1000020,ALL,17,0X400200E0,0X20020,ALL,17,0X400100E0,0X10020,ALL,17,0,0,ALL,24^END_FOXV=  ^aname=NULL^alevel=0^action=EXECUTE^required=0^cmd== P4 V_0001 ; = P5 00TZ_1009 ; = P6 1 ; script /opt/script/MTF/ovlCIN^oos_obj=0024"
        . userword 130

I then need to search on a tag number this is V_0001:00TZ_1005 and delete the 11 rows. can you help me ?
# 2  
Old 01-05-2011
Try something like this:
Code:
awk 'NR==FNR{if($0 ~ "V_0001:00TZ_1005"){n=NR}next} FNR < n-9 || FNR-n > 1' file file

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 01-05-2011
tried it doesn't do anything

source file is called V_0001.g

Code:
awk 'NR==FNR{if($0 ~ "V_0001:00TZ_1005"){n=NR}next} FNR < n-9 || FNR-n > 1' V_0001.g

i have tried it but no score :-)
# 4  
Old 01-05-2011
Use input file 2 times as given by Franklin

Code:
awk 'NR==FNR{if($0 ~ "V_0001:00TZ_1005"){n=NR}next} FNR < n-9 || FNR-n > 1' file file

This User Gave Thanks to pravin27 For This Post:
# 5  
Old 01-05-2011
that did the trick ! thanks guys great work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find to delete lines with pattern and even or odd number

In the below directory I am trying to delete all lines with a .bam extention that have the pattern IonCode_ followed by an even number. I am also trying to delete all lines with a .fastq extention that have the pattern IonCode_ followed by an odd number. I was going to use find but can see all... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. UNIX for Beginners Questions & Answers

Previous and Post lines in a pattern

Dear Community; I am posting this after looking at several solutions that were not fully relevant to the issue that I am facing. I have a large xml file, 100k+ lines which have patterns like below: <OfferDefinition Id="11"> <Type>Account</Type> ... (3 Replies)
Discussion started by: mystition
3 Replies

3. Shell Programming and Scripting

How to delete the previous line after pattern match?

Team, I am writing a shell script to perform few health checks of the system, where I need to delete the previous line in the text file after pattern match using sed (or) awk. Could you please help me out on this? For example, <td> <td style=color:green align=center> </td> </tr>... (6 Replies)
Discussion started by: Nagaraj R
6 Replies

4. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

5. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

6. Shell Programming and Scripting

Find and delete file previous to some date

Hello All, I have a directory containing of many .dat file, but with different naming conventions. I want to delete files which are created before and on 10th September 2013. I tried this command to see files which are are the files created before 10th September find path/to/file -type... (6 Replies)
Discussion started by: nnani
6 Replies

7. Shell Programming and Scripting

print range of lines matching pattern and previous line

Hi all, on Solaris 10, I'd like to print a range of lines starting at pattern but also including the very first line before pattern. the following doesn't print the range starting at pattern and going down to the end of file: cat <my file> | sed -n -e '/<pattern>{x;p;}/' I need to include the... (1 Reply)
Discussion started by: siriche
1 Replies

8. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

9. Shell Programming and Scripting

Need to delete previous lines

Need to delete the line which is directly above any line which has 3 fields in it. one two three one two three four five six four five six seven eight nine seven eight nine one two three should output: one two three (7 Replies)
Discussion started by: linuxkid
7 Replies

10. Shell Programming and Scripting

Search for a pattern in a file and print previous lines from a particular point

Hi, I am new to ksh scripting and I have a problem. I have a file in which I have to search for a particular pattern say 'a' then from that line I need to search for another pattern say 'b' in the previous lines and thne print the file from pattern 'b' till the end of file. For eg: ... (2 Replies)
Discussion started by: umaislearning
2 Replies
Login or Register to Ask a Question