LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replace new line with <br /> & escape special characters (https://www.linuxquestions.org/questions/linux-newbie-8/replace-new-line-with-br-and-escape-special-characters-861068/)

ted_chou12 02-06-2011 03:58 PM

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

stress_junkie 02-06-2011 04:36 PM

Here is a web page with string manipulation commands that are easy to use.
http://tldp.org/LDP/abs/html/string-manipulation.html

ted_chou12 02-06-2011 05:22 PM

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

Kenhelm 02-06-2011 05:55 PM

$'\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


chrism01 02-06-2011 08:23 PM

I'm pretty sure 'cut' only accepts a single char for the -d option. Try awk or sed or Perl for more complex replacements.

ted_chou12 02-07-2011 07:24 PM

thank you


All times are GMT -5. The time now is 02:01 PM.