LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 02-06-2011, 04:58 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
replace new line with <br /> & escape special characters


Hi, I wish to replace a new line with br (html) but it doesn't seem to work
Code:
Code:
message=$(echo ${FORM_message} | tr '\r' '<br \/>' )
what it gives me seems to be ... b...?


I am also having problem escaping hash sign in cut command:
Code:
Code:
list=$(echo "$line" | cut -d'\#;\#' -f1) ;
my intention is to split the line with "#;#"
thanks
 
Old 02-06-2011, 05:36 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Here is a web page with string manipulation commands that are easy to use.
http://tldp.org/LDP/abs/html/string-manipulation.html
 
Old 02-06-2011, 06:22 PM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
thanks, but the problem is i dont know which command to use. i m trying everything i can find for example
Code:
message=$(echo ${FORM_message//\r/\<br\>})
doesnt work, it doesnt detect for new lines
 
Old 02-06-2011, 06:55 PM   #4
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 333

Rep: Reputation: 141Reputation: 141
$'\n' gives a newline character in bash
Code:
FORM_message='line 1
line 2
line 3'

message="${FORM_message//$'\n'/<br>}"
echo "$message"
line 1<br>line 2<br>line 3

# Or the newline can be put in using the return key
message="${FORM_message//
/<br>}"
echo "$message"
line 1<br>line 2<br>line 3
 
Old 02-06-2011, 09:23 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
I'm pretty sure 'cut' only accepts a single char for the -d option. Try awk or sed or Perl for more complex replacements.
 
Old 02-07-2011, 08:24 PM   #6
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
thank you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Amarok & special characters in filenames BroX Slackware 4 04-29-2010 12:10 PM
search and replace string having multiple special characters say_hi_ravi Linux - Newbie 4 08-26-2009 08:43 AM
How do I replace special characters in a string within a bash script? rhaup0317 Linux - Newbie 2 06-03-2008 12:56 PM
How to modify the names of files and replace characters with other characters or symb peter88 Linux - General 2 12-10-2006 04:05 AM
Rsync & special characters strakkejakke Linux - Software 0 02-09-2005 02:52 PM


All times are GMT -5. The time now is 09:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration