Sponsored Content
Top Forums Shell Programming and Scripting Find pattern a delete previous 5 lines Post 302485446 by EjjE on Wednesday 5th of January 2011 08:39:02 AM
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 ?
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
scandir(3C)															       scandir(3C)

NAME
scandir(), alphasort() - scan a directory SYNOPSIS
DESCRIPTION
reads the directory dirname and builds an array of pointers to directory entries using (see malloc(3C)). It returns the number of entries in the array and a pointer to the array through namelist. The select parameter is a pointer to a user-supplied subroutine which is called by to select which entries are to be included in the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be included in the array. If select is null, then all the directory entries will be included. The compar parameter is a pointer to a user-supplied subroutine which is passed to qsort(3C) to sort the completed array. If this pointer is null, the array is not sorted. is a routine which can be used for the compar parameter to sort the array alphabetically. EXTERNAL INFLUENCES
Locale The category determines the collation ordering used by The category determines the interpretation of bytes in the file name portion of directory entries as single- and/or multi-byte characters by the function. Results are undefined if the locales specified by the and categories use different code sets. International Code Set Support Single- and multi-byte character code sets are supported for RETURN VALUE
If successful, returns the number of directory entries selected, and through the namelist parameter returns a pointer to the array. returns -1, if the directory cannot be opened for reading or cannot allocate enough memory to hold all the data structures. APPLICATION USAGE
uses to allocate memory for the array associated with the namelist pointer. If the return value of is greater than or equal to zero(0), memory allocated for the namelist pointer needs to be freed by the application using (see malloc(3C)) by first freeing each pointer in the array followed by the array itself. EXAMPLES
The example program below scans the directory. It does not exclude any entries since select is NULL. The contents of are sorted by It prints out how many entries are in and the sorted entries of the directory. The memory used by is returned using #include <sys/types.h> #include <stdio.h> #include <dirent.h> extern int scandir(); extern int alphasort(); main() { int num_entries, i; struct dirent **namelist, **list; if ((num_entries = scandir("/tmp", &namelist, NULL, alphasort)) < 0) { fprintf(stderr, "Unexpected error "); exit(1); } printf("Number of entries is %d ", num_entries); if (num_entries) { printf("Entries are:"); for (i=0, list=namelist; i<num_entries; i++) { printf(" %s", (*list)->d_name); free(*list); list++; } } free(namelist); printf(" "); exit(0); } WARNINGS
For 32-bit applications, the d_ino field of the struct returned by or may overflow for filesystems that use 64-bit values. In this case the most-significant bytes will be truncated without generating an error and d_ino values may not be unique. SEE ALSO
directory(3C), malloc(3C), qsort(3C), string(3C), dirent(5), thread_safety(5). scandir(3C)
All times are GMT -4. The time now is 12:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy