11-28-2008
replacing strings with newlines : sed
Hi everyone,
Since the previous time I received help from unix.com I have been encouraged to learn more.
going through 1 of the articles
(View Article) on sed I found, it pointed an interesting situation.
Suppose the text is :
Romeo and Ethel the Dancer Moves Audience to Tears.
I was treated to the off Broadway opening of Romeo and Ethel the
Dancer. This moving story of star-crossed lovers had the
audience in tears half way through the third act.
Do not go to see this play without a hanky, but even the weeping
from the back row could not diminish the brilliance of Romeo and
Ethel the Dancer by William Shakespeare.
Now I want to replace "Romeo and Ethel the Dancer" by "Romeo and Juliet".
The lines are separated by newlines.
The article demontrates doing this by using addresses. I was trying to think of another way round by building a reg-ex and use simple sed.
I believe I need a way to represent a newline in the sed search expression.
Please help by hinting towards the solution and not directly.
Thank You.
Regards
Last edited by hkansal; 11-28-2008 at 01:27 PM..
Reason: Added link back to original article
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All,
silly question that I'm sure is easy to answer for a more experienced coder...
I have a file called test.txt containing the following text...
need, to, break, this, line, into, individual, lines
using sed, I'd like to make the file look like this...
need
to
break
this
line... (5 Replies)
Discussion started by: newbie_coder
5 Replies
2. UNIX for Dummies Questions & Answers
Hi all,
I have a script which uses sed to replace one string with another. The problem is, the string to be matched, and its replacement are coming in as two command line arguments $1 and $2
$1 and $2 can be absolutely anything, but both should be treated purely as strings. My sed command... (1 Reply)
Discussion started by: mark007
1 Replies
3. UNIX for Dummies Questions & Answers
Guyz
I have been using tr command to replace symbol.
I would like to add a symbol to all newlines in a textfile with out replacing them
input
\n (i mean new line)
a
\n
b
\n
c
output
>
a
>
b
>
c (0 Replies)
Discussion started by: repinementer
0 Replies
4. UNIX for Dummies Questions & Answers
Hi guys,
say I have a few files in a directory (58 text files or somthing)
each one contains mulitple strings that I wish to replace with other strings
so in these 58 files I'm looking for say the following strings:
JAM (replace with BUTTER)
BREAD (replace with CRACKER)
SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies
5. Shell Programming and Scripting
The code below gives the string "test1.txt" even though "tessdsdt" does not match "test1.txt". I would like to return "" if there is no match and return some kind of error that I can capture and decide what to do.
echo test1.txt | awk -v src="tessdsdt" -v dst="test" '{sub(src,dst); print}' (16 Replies)
Discussion started by: kristinu
16 Replies
6. Shell Programming and Scripting
Hi all,
i am getting count from oracle 11g by spooling it to a file.
Now there are some newline characters and blank spaces i need to remove these.
pl provide me a awk/sed solution.
the spooled file is attached.
i tried this.. but not getting req o/p (6 Replies)
Discussion started by: rishav
6 Replies
7. Shell Programming and Scripting
hi
i have a requirement to replace a string with another using sed and to get the result newline separated but after sed replacement the newline vanishes
below is sample code
#!/bin/ksh
set -x
string="name sam\nage 45 \nsport soccer"
echo $string
string=`echo $string | sed... (2 Replies)
Discussion started by: midhun19
2 Replies
8. Shell Programming and Scripting
Hello All,
I have two files with delimited |
file 1 :
1|2|3
11|12|13
22|23|24
and file 2 :
1|4|5|6
11|14|15|16
22|25|26
I want to replace the value '1' in file 2 with the values in file 1 '1|2|3'
so the final output will look like
1|2|3|4|5|6
11|12|13|14|15|16
22|23|24|25|26 (3 Replies)
Discussion started by: ArunKumarM
3 Replies
9. Shell Programming and Scripting
Here is the text that I was to run sed on. In this text I want to insert a semi colon ';' before 'select a13.STORE_TYPE STORE_TYPE,' and after 'from ZZMR00 pa11'
Input text:
insert into ZZMQ01
select pa11.STATE_NBR STATE_NBR,
pa11.STORE_TYPE STORE_TYPE,
... (9 Replies)
Discussion started by: v_vineeta11
9 Replies
10. Shell Programming and Scripting
I have a file that look like this:
>Muestra-1
agctgcgagctgcgaccc
gggttatata
ggaagagacacacacaccccc
>Muestra-2
agctgcg
agctgcgacccgggttatataggaagagac
acacacaccccc
>Muestra-3
agctgcgagctgcgaccc
gggttatata
ggaagagacacacacaccccc
I use the following sed script to remove newlines from... (2 Replies)
Discussion started by: Xterra
2 Replies
LEARN ABOUT DEBIAN
dancer::object::singleton
Dancer::Object::Singleton(3pm) User Contributed Perl Documentation Dancer::Object::Singleton(3pm)
NAME
Dancer::Object::Singleton - Singleton base class for Dancer
SYNOPSIS
package My::Dancer::Extension;
use strict;
use warnings;
use base 'Dancer::Object::Singleton';
__PACKAGE__->attributes( qw/name value this that/ );
sub init {
my ($class, $instance) = @_;
# our initialization code, if we need one
}
# .. later on ..
# returns the unique instance
my $singleton_intance = My::Dancer::Extension->instance();
DESCRIPTION
Dancer::Object::Singleton is meantto be used instead of Dancer::Object, if you want your object to be a singleton, that is, a class that
has only one instance in the application.
It provides you with attributes and an initializer.
METHODS
instance
Returns the instance of the singleton. The instance is created only when needed. The creation will call the "init()" method, which you
should implement.
init
Exists but does nothing. This is so you won't have to write an initializer if you don't want to. init receives the instance as argument.
get_attributes
Get the attributes of the specific class.
attributes
Generates attributes for whatever object is extending Dancer::Object and saves them in an internal hashref so they can be later fetched
using "get_attributes".
AUTHOR
Damien Krotkine
LICENSE AND COPYRIGHT
Copyright 2010 Damien Krotkine.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as
published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
perl v5.14.2 2011-11-30 Dancer::Object::Singleton(3pm)