How to replace one character with two characters using tr

前端 未结 5 1531
栀梦
栀梦 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:17

    you could go with awk, let FS/OFS variable do the job for you:

    awk -F'~' -v OFS="~\n" '$1=$1' 
    

    test with your example:

    kent$ awk -F'~' -v OFS="~\n" '$1=$1' <<< "asdlksad ~ adlkajsd ~ 12345" 
    asdlksad ~
     adlkajsd ~
     12345
    

提交回复
热议问题