Removing Lines that Contain a Certain String


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing Lines that Contain a Certain String
# 1  
Old 06-02-2014
Removing Lines that Contain a Certain String

I'm writing a UNIX script to interpret text files and search for certain strings to output and need to delete certain lines that contain characters that I would like removed from the file. The rest of the script is already completed and I have it output how I would like, but I cannot seem to get this part to work how I want it to.

I would like the program to delete the next 10 lines after the phrase "12: " (with the space, but without the quotations) appears. I currently have written
Code:
sed 'Re: /d'

, but that doesn't seem to work; I just get the error message "sed: can't read /Re: /d: No such file or directory" when trying to run the script on a file.

If you could explain to me how to delete a line containing that string or, better yet, how to delete that line followed by the next 10 lines, it would be much appreciated.
# 2  
Old 06-02-2014
Welcome to forums, you can try something like this if you have awk

Code:
$ awk '/pattern_to_search/{s = FNR+10}FNR>=s' file

if this doesn't work then please provide sample input.
# 3  
Old 06-03-2014
Have a look at your manual page for grep If it supports the -A flag, then that may do just what you need.


Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing string from CSV file by provide removal string from other file

What I need is to remove the text from Location_file.txt from each line matching all entries from Remove_location.txt Location_file.txt FlowPrePaid, h3nmg1cm2,Jamaica_MTAImageFileFlowPrePaid,h0nmg1cm1, Flow_BeatTest,FlowRockTest FlowNewTest,FlowNewTest,h0nmg1cm1 PartiallySubscribed,... (3 Replies)
Discussion started by: ketanraut
3 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

4. UNIX for Dummies Questions & Answers

Removing PATTERN from txt without removing lines and general text formatting

Hi Everybody! First post! Totally noobie. I'm using the terminal to read a poorly formatted book. The text file contains, in the middle of paragraphs, hyphenation to split words that are supposed to be on multiple pages. It looks ve -- ry much like this. I was hoping to use grep -v " -- "... (5 Replies)
Discussion started by: AxeHandle
5 Replies

5. Shell Programming and Scripting

removing lines without text

How do I remove line that do not contain text, but that do contain tabs? I have tried the command cat file | awk NF but that doesn't work when the lines contain tabs (and spaces). I have also tried: cat file | sed '/^$/d' (9 Replies)
Discussion started by: locoroco
9 Replies

6. Shell Programming and Scripting

Removing a bunch of lines

I have a file that contains the following multiple times: 0<< bla bla bla bla bla bla exit; Can somebody give me a sed or AWK command I can use to remove all occurances from this file. I would like it to find 0<< (note the zero may be proceeded by spaces) and remove that line and... (3 Replies)
Discussion started by: BeefStu
3 Replies

7. Shell Programming and Scripting

Removing last two lines

I have an awk script that replaces ">" with % %> %< SOURCE", ++i %( PHASE 1", i I use the following script />/ { if ( FNR > 1 ) { print "%)" print "%>" } print "" print "%< SOURCE", ++i (11 Replies)
Discussion started by: kristinu
11 Replies

8. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

9. Shell Programming and Scripting

Removing lines having #

I have a script which goes to different directories and gives the values of all the input parameters, Something as follows cd /opt grep script-filter = yes *.conf grep user-and-group-in-same-suffix = yes *.conf grep worker-threads = 300 *.conf grep failover-auth = *.conf grep... (9 Replies)
Discussion started by: openspark
9 Replies

10. Shell Programming and Scripting

Removing duplicates from string (not duplicate lines)

please help me in getting following: Input Desired output x="foo" foo x="foo foo" foo x="foo foo" foo x="foo abc foo" foo abc x="foo foo1 foo2" foo foo1 foo2 I need to remove duplicated from string.. (8 Replies)
Discussion started by: vickylife
8 Replies
Login or Register to Ask a Question