02-12-2011
Using Bash/Sed to delete between identical strings
Hi. I'm hoping that someone can help me with a bash script to delete a block of lines from a file.
What I want to do is delete every line between two stings that are the same,
including the line the first string is on but not the second.
(Marked lines to match with !)
For example if I have:
fish
! cat
dog
ferret
lion
etc
! cat
kitten
zebra
What I'm looking to get is:
fish
cat
kitten
zebra
I've been trying to work out how to do this with sed but haven't had much luck.
Some 3-4 hours in, the closest I've gotten is deleting between the strings, or deleting both strings.
Thanks for reading. -Zykr
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am looking to replace two or more strings on different lines using sed, but not with the same variable. IE
# cat xxx.file
<abc>
abc def ghi
abc def ghi
abc def ghi
currently I can only change each line with the same pattern:
# sed -e '/<abc>/!s/abc\(.*\)/jkl mno/' xxx.file
abc jkl mno... (3 Replies)
Discussion started by: prkfriryce
3 Replies
2. SuSE
i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings...
for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies
3. Programming
i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings...
for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies
4. Shell Programming and Scripting
i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings...
for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies
5. Shell Programming and Scripting
Hi. I have to delete the content between all the occurrences of the xml tags in a single file.
For example:
* The tags <script>.....................</script> occurs more than once in the same file.
* It follows tagging rules meaning a start tag will be followed by an end tag. Will not have... (9 Replies)
Discussion started by: satheeshkumar
9 Replies
6. Shell Programming and Scripting
Hi guys, I wonder if it's possible to search for a line containing 2 strings and delete that line and perhaps replace the source file with already deleted line(s).
What I mean is something like this:
sourcefile.txt
line1: something 122344 somethin2 24334 45554676
line2: another something... (6 Replies)
Discussion started by: netrom
6 Replies
7. Shell Programming and Scripting
Hi,
I have two files: a.doc and b.txt
I wish to search the strings from file b.txt in a.doc and want to highlight them in a.doc with different colours using Perl or bash./awk/sed?
Please guide me. :)
Thanks!!!!! (10 Replies)
Discussion started by: bioinfo
10 Replies
8. Ubuntu
Hi
I have a data frame with repeated names in column 1, and different descriptors in column 2. I want to merge/cat strings that have same entry in column 1 into one row with any separator.
Example for input:
Cvel_1 KOG0155
Cvel_1 KOG0306
Cvel_1 KOG3259
Cvel_1 ... (4 Replies)
Discussion started by: Alyaa
4 Replies
9. Shell Programming and Scripting
hey,
i m having a hard time trying to print only the first occurrence between 2 idenicale strings.
for the following output:
please
help
me im a
noob
please
im a noob
help me
noob
please
help
me im a
noob
please
im a noob
help me
noob (3 Replies)
Discussion started by: boaz733
3 Replies
10. UNIX for Beginners Questions & Answers
Hi,
I have a file as follows.
file1
Hello
Hi
His
Hi
Hi
Hungry
hi
so I want to delete identical lines while leaving one of them undeleted.
So desired output will be
Hello
Hi (2 Replies)
Discussion started by: beginner_99
2 Replies
ZEBRA(8) Version 0.97.3 ZEBRA(8)
NAME
zebra - a routing manager for use with associated Quagga components.
SYNOPSIS
zebra [ -bdhklrv ] [ -f config-file ] [ -i pid-file ] [ -P port-number ] [ -A vty-address ] [ -u user ] [ -g group ]
DESCRIPTION
zebra is a routing manager that implements the zebra route engine. zebra supports RIPv1, RIPv2, RIPng, OSPF, OSPF6, IS-IS, BGP4+, and
BGP4-.
OPTIONS
Options available for the zebra command:
-b, --batch
Runs in batch mode, zebra parses its config and exits.
-d, --daemon
Runs in daemon mode, forking and exiting from tty.
-f, --config-file config-file
Specifies the config file to use for startup. If not specified this option will likely default to /usr/local/etc/zebra.conf.
-g, --group group
Specify the group to run as. Default is quagga.
-h, --help
A brief message.
-i, --pid_file pid-file
When zebra starts its process identifier is written to pid-file. The init system uses the recorded PID to stop or restart zebra.
The likely default is /var/run/zebra.pid.
-k, --keep_kernel
On startup, don't delete self inserted routes.
-P, --vty_port port-number
Specify the port that the zebra VTY will listen on. This defaults to 2601, as specified in /etc/services.
-A, --vty_addr vty-address
Specify the address that the zebra VTY will listen on. Default is all interfaces.
-u, --user user
Specify the user to run as. Default is quagga.
-r, --retain
When the program terminates, retain routes added by zebra.
-s, --nl-bufsize netlink-buffer-size
Set netlink receive buffer size. There are cases where zebra daemon can't handle flood of netlink messages from kernel. If you ever
see "recvmsg overrun" messages in zebra log, you are in trouble.
Solution is to increase receive buffer of netlink socket. Note that kernel doesn't allow to increase it over maximum value defined
in /proc/sys/net/core/rmem_max. If you want to do it, you have to increase maximum before starting zebra.
Note that this affects Linux only.
-v, --version
Print the version and exit.
FILES
/usr/local/sbin/zebra
The default location of the zebra binary.
/usr/local/etc/zebra.conf
The default location of the zebra config file.
$(PWD)/zebra.log
If the zebra process is config'd to output logs to a file, then you will find this file in the directory where you started zebra.
WARNING
This man page is intended to be a quick reference for command line options. The definitive document is the Info file Quagga.
DIAGNOSTICS
The zebra process may log to standard output, to a VTY, to a log file, or through syslog to the system logs. zebra supports many debugging
options, see the Info file, or the source for details.
SEE ALSO
bgpd(8), ripd(8), ripngd(8), ospfd(8), ospf6d(8), isisd(8), vtysh(1)
BUGS
zebra eats bugs for breakfast. If you have food for the maintainers try http://bugzilla.quagga.net
AUTHORS
See http://www.zebra.org and http://www.quagga.net or the Info file for an accurate list of authors.
Zebra daemon 25 November 2004 ZEBRA(8)