Seemingly simple sed, delete between matching lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Seemingly simple sed, delete between matching lines
# 1  
Old 06-23-2016
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
Code:
Searching Checks. Based on search criteria
name: Value :  CPU
name: Value :  Memory
name: Value :  RX_Errors
name: Value :  RX_Errors1
name: Value :  TX_Errors
name: Value :  TX_Errors1
name: Value : ACE thresholds - Access List Limit
name: Value : ACI Fabric - DVS has been deleted
name: Value : ACI LAS-F01 - IS-IS Route Adjacencies Lost
name: Value : IVR Hours Of Operation 
name: Value : IVR Hours Of Operation - 
name: Value : Glance Cobrowse Waiting Check
name: Value : Glance Video Check
name: Value : DP_GLUSTER_DISK_IO_STAT
name: Value : Carbon_CPU

Moderator's Comments:
Mod Comment Please use code tags for output/data too, as required by forum rules!



I want to remove the entire block. Here are some examples I have tested but am unable to remove the block of text. Any ideas?
Code:
#!/bin/bash -x 

#The below line works
sed '/two/,/nine/d' newnumber > 1number 

#This line works
#sed -i 's/Searching Checks.*name: Value : Carbon_CPU//g' test1 > 3test

#name: Value :  TX_Errors1
#sed -i 's/Searching Checks.*name: Value :  TX_Errors1//g' test1 > 3test

sed '/Searching Checks.\ Based\ a\ search\ criteria/,/name:\ Value\ :\ Carbon_CPU/d' test1 >> 4test 
#These may not work
#sed '/Searching Checks. Based a search criteria/,/name: Value : Carbon_CPU/d' test1


Last edited by RudiC; 06-24-2016 at 04:10 AM.. Reason: Added code tags.
# 2  
Old 06-23-2016
Last line should work but with a minor modification:

sed '/Searching Checks. Based on search criteria/,/name: Value : Carbon_CPU/d' test1
This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 06-24-2016
I also had to use
Code:
:set list

in vi to show hidden characters. In my case it only showed the end line character which we know is in place anyway. I cut and pasted back into my script and that is what is took in addition to correcting my typo. Including the $ end line character should not be necessary but that is what it took to make this run.

Code:
sed '/Searching Checks. Based on search criteria$/,/name: Value :  TX_Errors1$/d' test1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all lines from file matching a string

I wish to search and delete all lines in /app/Jenkins/deploy.txt having this filename string /app/Jenkins/file2.mrt as entry: I'm using : colon as delimiter in sed command as I'm dealing with file paths. Below is the command I was expecting to work. sed -i ":/app/Jenkins/file2.mrt:d"... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Regular expression, seemingly simple but

Hello, I want to test a hour variable with an expression regular The format is 00 01 02 03.......19 20 21 22 23 what follows in red doesn't work, it's clear 19 for example can't work. Can you help me the right regular expression ? case "$3" in () # Nothing, OK ! ;; (*) echo... (4 Replies)
Discussion started by: amazigh42
4 Replies

3. UNIX for Dummies Questions & Answers

delete lines matching a regular expression

I have a very large file (over 700 million lines) that has some lines that I need to delete. An example of 5 lines of the file: HS4_80:8:2303:19153:193032 153 k80:138891 HS4_80:8:2105:5544:43174 89 k88:81949 165 k88:81949 323 0 * = 323 0 ... (6 Replies)
Discussion started by: pathunkathunk
6 Replies

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

5. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

6. Shell Programming and Scripting

Delete lines upto matching path variable

I have a script that if it crashes I want it to start again where it stopped. The way to identify the tasklist is using a find command that list all the files that need the process performed on them TASKLIST=`find /path/to/directory -iname *.dummy | sort` The way to identify the... (6 Replies)
Discussion started by: Bashingaway
6 Replies

7. Shell Programming and Scripting

delete lines in file matching a pattern

I have a text file, a sample of which is as follows: r/- * 0: WINDOWS/Microsoft.NET/Framework/v2.0.50727/ASP.NETWebAdminFiles/Images/headerGRADIENT_Tall.gif r/- * 0: WINDOWS/SoftwareDistribution/Download/cf8ec753e88561d2ddb53e183dc05c3e/backoff.jpg r/- * 0: ... (2 Replies)
Discussion started by: stumpyuk
2 Replies

8. Shell Programming and Scripting

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: ProcessType: PROCESS_A... (5 Replies)
Discussion started by: Juha
5 Replies

9. UNIX for Dummies Questions & Answers

How do you delete files that are seemingly missing inodes?

I have some files that appear to have no inode numbers. To complicate the matter, the filenames have UTF8 (I think) characters. I am trying to delete them. In fact, and this might make things easier, I'm trying to delete their parent directory. I don't know what to try next, please help. ... (5 Replies)
Discussion started by: jaffachamp
5 Replies

10. 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
Login or Register to Ask a Question