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

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:

list=$(echo "$line" | cut -d'\#;\#' -f1) ;

my intention is to split the line with "#;#"
thanks

You are using the cut and tr utilities in an unappropriated way.
They work with single characters in the delimiters instead of multicharacters. Moreover, it is possible that they are not even the right tools for the job.

message=$(echo ${FORM_message} | sed  's!\r!<br \/>!' )

sed could be a better option here.

list=$(echo "$line" | awk -F"#"  '{print $1}' ) ;

awk could be a better option here.

These are JUST examples. The correct syntax depends of the input format

1 Like

thanks