sed - Replace \n(new line) with space in bash -


i reading sql queries variable db , contains new line character (\n). want replace \n (new line) space. tried solutions provided on internet unsuccessful achieve want. here tried :

strr="my\nname\nis\nxxxx"; nw_strr=`echo $strr | tr '\n' ' '`; echo $nw_strr; 

my desired output "my name xxxx" getting "my\nname\nis\nxxxx". tried other solution provided @ internet, no luck:

nw_strr=`echo $strr | sed ':a;n;$!ba;s/\n/ /g'`; 

am doing wong?

with bash:

replace newlines space:

nw_strr="${strr//$'\n'/ }" 

replace strings \n space:

nw_strr="${strr//\\n/ }" 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -