How to replace one character with two characters using tr

前端 未结 5 1528
栀梦
栀梦 2020-12-17 08:10

Can tr replace one character with two characters?

I am trying to replace \"~\" with \"~\\n\" but the output does not produce the newline.

$ echo \"a         


        
5条回答
  •  伪装坚强ぢ
    2020-12-17 08:12

    tr can only do 1 to 1 translation.

    Here is one way of doing that using pure Bash:

    s='"asdlksad ~ adlkajsd ~ 12345'
    r=$'~\n'
    echo -e "${s//\~/$r}"
    asdlksad ~
     adlkajsd ~
     12345
    

提交回复
热议问题