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::logger
Dancer::Logger(3pm) User Contributed Perl Documentation Dancer::Logger(3pm)
NAME
Dancer::Logger - common interface for logging in Dancer
DESCRIPTION
This module is the wrapper that provides support for different logger engines.
USAGE
Default engine
The setting logger defines which logger engine to use. If this setting is not set, logging will not be available in the application code.
Dancer comes with the logger engines Dancer::Logger::File and Dancer::Logger::Console, but more are available on the CPAN.
Configuration
The logger configuration variable tells Dancer which engine to use.
You can change it either in your config.yml file:
# logging to console
logger: "console"
Or in the application code:
# logging to file
set logger => 'file';
The log format can also be configured, please see "logger_format" in Dancer::Logger::Abstract for details.
Auto-serializing
The loggers allow auto-serializing of all inputs:
debug( 'User credentials: ', \%creds );
Will provide you with an output in a single log message of the string and the reference dump.
AUTHORS
This module has been written by Alexis Sukrieh. See the AUTHORS file that comes with this distribution for details.
LICENSE
This module is free software and is released under the same terms as Perl itself.
SEE ALSO
See Dancer for details about the complete framework.
You can also search the CPAN for existing engines in the Dancer::Logger namespace :
<http://search.cpan.org/search?query=Dancer%3A%3ALogger>.
perl v5.14.2 2012-04-01 Dancer::Logger(3pm)