Sponsored Content
Top Forums UNIX for Dummies Questions & Answers sed [delete everything between two words] Post 302153537 by drl on Tuesday 25th of December 2007 07:12:54 AM
Old 12-25-2007
Hi.

With sed:
Code:
#!/usr/bin/env sh

# @(#) s1       Demonstrate delete lines of range exclusive.
# This solution based on code tutorial at:
# http://sed.sourceforge.net/sedfaq.html
# 2007.12.25

set -o nounset
echo

debug=":"
debug="echo"

## Use local command version for the commands in this demonstration.

echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version bash sed

echo

FILE=${1-data1}
echo " Input file $FILE:"
cat $FILE

echo
echo " Results from sed:"
sed '/WISH_LIST="/,/^"$/{
/WISH_LIST="/b
/^"$/b
d
}' $FILE

exit 0

Producing:
Code:
% ./s1

(Versions displayed with local utility "version")
GNU bash 2.05b.0
GNU sed version 4.1.2

 Input file data1:
hello
start
WISH_LIST="
candy
money
t-shirt
"
stop
cool
Christmas

 Results from sed:
hello
start
WISH_LIST="
"
stop
cool
Christmas

A tip of the hat to Eric Pement ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed option to delete two words within a file

Could someone please help me with the following. I'm trying to figure out how to delete two words within a specific file using sed. The two words are directory and named. I have tried the following: sed '//d' sedfile sed '//d' sedfile both of these options do not work..... ... (4 Replies)
Discussion started by: klannon
4 Replies

2. UNIX for Advanced & Expert Users

How to delete first 10 words from file

Hi, Could you please let me know, how to delete first 10 words from text files using vi? 10dw will delete it from current line, how to do it for all the lines from file? Thanks (6 Replies)
Discussion started by: sentak
6 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. UNIX for Dummies Questions & Answers

sed how to delete between two words within a file

I'm hoping someone could help me out please :) I have several .txt files with several hundred lines in each that look like this: 10241;</td><td>10241</td><td class="b">x2801;</td><td>2801</td><td>TEXT-1</td></tr> 10242;</td><td>10242</td><td... (4 Replies)
Discussion started by: martinsmith
4 Replies

5. Shell Programming and Scripting

Delete between two words

Hi, I wanted to delete data between two words. Input: I read gihoihsahkjlk write goal hard read hsakdjhkh write work read hlkhlkhlkh write Desired Output: I write goal hard write work write We have to replace the data that comes between 'read' and 'write' with... (3 Replies)
Discussion started by: mahish20
3 Replies

6. Shell Programming and Scripting

Using Sed to Delete Words in a File

This is a Nagios situation. So i have a list of servers in one file called Servers.txt And in another file called hostgroups.cfg, i want to remove each and every one of the servers in the Servers.txt file. The problem is, the script I wrote is having a problem removing the exact servers in... (5 Replies)
Discussion started by: SkySmart
5 Replies

7. Shell Programming and Scripting

SED - delete words between two possible words

Hi all, I want to make an script using sed that removes everything between 'begin' (including the line that has it) and 'end1' or 'end2', not removing this line. Let me paste an 2 examples: anything before any string begin few lines of content end1 anything after anything before any... (4 Replies)
Discussion started by: meuser
4 Replies

8. UNIX for Dummies Questions & Answers

Delete all words not containing letter /s/

I have a word file that looks like: pens binder spiral user I want to delete all the words without the letter /s/, so output looks like: pens spiral user I tried using sed: sed '//d' infile.txt > out.txt (5 Replies)
Discussion started by: pxalpine
5 Replies

9. Shell Programming and Scripting

Delete some words

hi, i have a fasta file like this: >contig00003 length=363 numreads=45 gene=isogroup00001 status=it_thresh GATTTTTTACCCTGGGAGTGAGGAGGACGAGGTTGAGGATGAAGAAAAGAGAAAGATGAAGAGGTTGAGGATGTT GTAGTCGGCGGTGGAATTAGGGGGAGCCGGCGAGCCCAAGTATTTTGCAGAGGTGTCTTCATCATCCAAACAACA... (3 Replies)
Discussion started by: the_simpsons
3 Replies

10. UNIX for Dummies Questions & Answers

Delete between two words

So;C951;1;2;0;100;true;SNetwork=ORM_RO_MO_R,MeCext=C5951,ManagedElement=1,vsDaFunction=1;473;12;EEE So;C951;2;2;0;100;true;SNetwork=ORM_RO_MO_R,MeCext=L5921,ManagedElement=1,vsDaFunction=4;481;12;EEE Output:- So;C951;1;2;0;100;true;1;473;12;EEE So;C951;2;2;0;100;true;4;481;12;EEE Output... (7 Replies)
Discussion started by: pareshkp
7 Replies
ECHO(1) 							   User Commands							   ECHO(1)

NAME
echo - display a line of text SYNOPSIS
echo [SHORT-OPTION]... [STRING]... echo LONG-OPTION DESCRIPTION
Echo the STRING(s) to standard output. -n do not output the trailing newline -e enable interpretation of backslash escapes -E disable interpretation of backslash escapes (default) --help display this help and exit --version output version information and exit If -e is in effect, the following sequences are recognized: \ backslash a alert (BEL)  backspace c produce no further output e escape f form feed new line carriage return horizontal tab v vertical tab NNN byte with octal value NNN (1 to 3 digits) xHH byte with hexadecimal value HH (1 to 2 digits) NOTE: your shell may have its own version of echo, which usually supersedes the version described here. Please refer to your shell's docu- mentation for details about the options it supports. GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report echo translation bugs to <http://translationproject.org/team/> AUTHOR
Written by Brian Fox and Chet Ramey. COPYRIGHT
Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for echo is maintained as a Texinfo manual. If the info and echo programs are properly installed at your site, the command info coreutils 'echo invocation' should give you access to the complete manual. GNU coreutils 8.22 June 2014 ECHO(1)
All times are GMT -4. The time now is 01:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy