Sponsored Content
Top Forums Shell Programming and Scripting SED: delete matching row and 4 next rows? Post 302299074 by Juha on Thursday 19th of March 2009 06:27:49 AM
Old 03-19-2009
SED: delete matching row and 4 next rows?

Hi,

Tried to look for solution, and found something similar but could not adapt the solution for my needs..

I'm trying to match a pattern (in this case "ProcessType")in a logfile, then delete that line and the 4 following lines.

The logfile looks as follows:
Code:
ProcessType:    PROCESS_A (0) <---- delete this
SequenceNumber: 8285 <---- delete this
 <---- delete this
2009 Mar 07  22:04:23:679   0:8285 <---- delete this
 <---- delete this
ProcessType:    PROCESS_A (0)
SequenceNumber: 8286

2009 Mar 07  22:04:23:679   0:8286

ProcessType:    PROCESS_B (68)
SequenceNumber: 40689

2009 Mar 07  22:04:23:698  68:40689

DATA that should not be deleted

ProcessType:    PROCESS_B (68)
SequenceNumber: 40690

2009 Mar 07  22:04:23:698  68:40690

DATA that should not be deleted

ProcessType:    PROCESS_C (93)
SequenceNumber: 36235

2009 Mar 07  22:04:23:829  93:36235

ProcessType:    PROCESS_C (93)
SequenceNumber: 36236

2009 Mar 07  22:04:23:829  93:36236

DATA that should not be deleted

I tried this:

Code:
sed -e '/\<ProcessType\>/,/$/d' < log.txt > test

But that only resulted in this:

Code:
2009 Mar 07  22:04:23:679   0:8285


2009 Mar 07  22:04:23:679   0:8286


2009 Mar 07  22:04:23:698  68:40689


2009 Mar 07  22:04:23:698  68:40690


2009 Mar 07  22:04:23:829  93:36235


2009 Mar 07  22:04:23:829  93:36236


2009 Mar 07  22:04:23:945  91:89062


2009 Mar 07  22:04:23:945  91:89063


2009 Mar 07  22:04:24:018  91:89064


2009 Mar 07  22:04:24:018  91:89065


2009 Mar 07  22:04:24:018  91:89066

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to delete row

I want to use sed command to delete a matched row with a pattern. And I also want to delete previous and next row of that row. Which option can I use with sed ? (9 Replies)
Discussion started by: anhtt
9 Replies

2. Shell Programming and Scripting

sed find matching pattern delete next line

trying to use sed in finding a matching pattern in a file then deleting the next line only .. pattern --> <ad-content> I tried this but it results are not what I wish sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml ex, <Celebrant2First>Mickey</Celebrant2First> <ad-content> Minnie... (2 Replies)
Discussion started by: aveitas
2 Replies

3. Shell Programming and Scripting

sed/awk: Delete matching words leaving only the first instance

I have an input text that looks like this (comes already sorted): on Caturday 22 at 10:15, some event on Caturday 22 at 10:15, some other event on Caturday 22 at 21:30, even more events on Funday 23 at 11:00, yet another event I need to delete all the matching words between the lines, from... (2 Replies)
Discussion started by: GrinningArmor
2 Replies

4. Shell Programming and Scripting

Combining multiple rows in single row based on certain condition using awk or sed

Hi, I'm using AIX(ksh shell). > cat temp.txt "a","b",0 "c",bc",0 "a1","b1",0 "cc","cb",1 "cc","b2",1 "bb","bc",2 I want the output as: "a","b","c","bc","a1","b1" "cc","cb","cc","b2" "bb","bc" I want to combine multiple lines into single line where third column is same. Is... (1 Reply)
Discussion started by: samuelray
1 Replies

5. Shell Programming and Scripting

Using sed (or awk or perl) to delete rows in a file

I have a Unix file with 200,000 records, and need to remove all records from the file that have the character ‘I' in position 68 (68 bytes from the left). I have searched for similar problems and it appears that it would be possible with sed, awk or perl but I do not know enough about any of these... (7 Replies)
Discussion started by: joddo
7 Replies

6. Shell Programming and Scripting

sed or awk delete character in the lines before and after the matching line

Sample file: This is line one, this is another line, this is the PRIMARY INDEX line l ; This is another line The command should find the line with “PRIMARY INDEX” and remove the last character from the line preceding it (in this case , comma) and remove the first character from the line... (5 Replies)
Discussion started by: KC_Rules
5 Replies

7. Shell Programming and Scripting

Awk/sed script for transposing any number of rows with header row

Greetings! I have been trying to find out a way to take a CSV file with a large number of rows, and a very large number of columns (in the thousands) and convert the rows to a single column of data, where the first row is a header representing the attribute name and the subsequent series of... (3 Replies)
Discussion started by: tntelle
3 Replies

8. Shell Programming and Scripting

Print various rows in one row

I have this in a file 11.22.33.44 yyyyyyuser With awk/sed, I need this to be output as follows alias server.domain.com='ssh yyyyyyuser@11.22.33.44' (4 Replies)
Discussion started by: anil510
4 Replies

9. Shell Programming and Scripting

Seemingly simple sed, delete between matching lines

There are many matching blocks of text in one file that need to be deleted. This example below is one block that needs to be either deleted or replaced with an empty line. This text below is the input file. The ouput file should be empty Searching Checks. Based on search criteria name: Value :... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

10. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies
Tcl_StringMatch(3tcl)					      Tcl Library Procedures					     Tcl_StringMatch(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_StringMatch, Tcl_StringCaseMatch - test whether a string matches a pattern SYNOPSIS
#include <tcl.h> int Tcl_StringMatch(str, pattern) int Tcl_StringCaseMatch(str, pattern, flags) ARGUMENTS
const char *str (in) String to test. const char *pattern (in) Pattern to match against string. May contain special characters from the set *?[]. int flags (in) OR-ed combination of match flags, currently only TCL_MATCH_NOCASE. 0 specifies a case-sensitive search. _________________________________________________________________ DESCRIPTION
This utility procedure determines whether a string matches a given pattern. If it does, then Tcl_StringMatch returns 1. Otherwise Tcl_StringMatch returns 0. The algorithm used for matching is the same algorithm used in the string match Tcl command and is similar to the algorithm used by the C-shell for file name matching; see the Tcl manual entry for details. In Tcl_StringCaseMatch, the algorithm is the same, but you have the option to make the matching case-insensitive. If you choose this (by passing TCL_MATCH_NOCASE), then the string and pattern are essentially matched in the lower case. KEYWORDS
match, pattern, string Tcl 8.5 Tcl_StringMatch(3tcl)
All times are GMT -4. The time now is 11:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy