The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
newline character trichyselva UNIX for Dummies Questions & Answers 9 10-31-2008 01:47 PM
replace a newline (\n) jeter Shell Programming and Scripting 3 05-18-2008 10:37 PM
delete newline character between html tags girish312 UNIX for Dummies Questions & Answers 8 02-29-2008 05:24 AM
Substituting carriage return followed by newline character - HELP djkane Shell Programming and Scripting 14 02-28-2006 09:58 PM
Newline character not working for ksh sanikv Shell Programming and Scripting 11 06-23-2005 01:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-16-2001
ghoti's Avatar
ghoti ghoti is offline
Registered User
  
 

Join Date: Jul 2001
Location: Wales
Posts: 55
How can I replace newline character?

Hi,

I am trying to write a script to prepare some text for use as web content.

What is happening is that all the newlines in the textfile are ignored, so I want
to be able to replace/add a few characters so that for a file containg:
Code:
This is line 1.
This is line two.

This is line four.
And this line is very long and covers more than two lines of text 
so there is no need to break it up in any way.
Another short line.
is is reformatted to become:
Code:
This is line 1.&ltbr&gt
This is line two.&ltbr&gt
&ltbr&gt
This is line four.&ltbr&gt
And this line is very long and covers more than two lines of text 
so there is no need to break it up in any way.&ltbr&gt
Another short line.&ltbr&gt
I have tried to use : tr "\n" "\n&ltbr&gt" but it will only replace with same number or fewer characters.

I tried using sed as well but was unable to find a way to search
for the newline character, I tried:

sed -e 's/\n/\n&ltbr&gt/g'
sed -e 's/^M/^M&ltbr&gt/g'
sed -e 's/\^M/\^M&ltbr&gt/g'

but they either do not work, or end up splitting the script line apart due to being taken as newline characters in the script. Is there any way to do this?

Thanks

PS, if it helps any, I am using a BASH shell on Redhat Linux 7.0

Last edited by ghoti; 08-16-2001 at 11:09 AM..
  #2 (permalink)  
Old 08-16-2001
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
below 2 code examples.

1) just add a &ltbr&gt at the end of EACH line that has a hard return @ the end.

2) add a &ltBR&gt at every "." followed by a hard return.

Code:
1) sed 's/$/\<BR\>/' test.html
2) sed 's/\.$/\BR\>/' test.html
also note. if you want a new line in sed its a 2 line script. you have to use a ^J to get it in there.

OR

if you wanted to use tr use the octal form of a hard return. \12 i think.

Last edited by Optimus_P; 08-16-2001 at 12:58 PM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0