【问题标题】:How do you split a long database string into multiple lines in a UNIX shell script?如何在 UNIX shell 脚本中将长数据库字符串拆分为多行?
【发布时间】:2020-12-12 15:25:27
【问题描述】:

我将下面的字符串存储在我的数据库列中:

"Your ack was rejected due to the following reason: \n -- Invalid code received. \n \n Please correct the error and resend."

\n 是我要在其中拆分行的换行符。

预期输出:

"Your ack was rejected due to the following reason:
-- Invalid code received.

Please correct the error and resend it."

请推荐 unix/sed 命令

【问题讨论】:

标签: unix sed


【解决方案1】:
echo $STRING| sed 's/\\n/\n/g

成功了!

【讨论】:

    【解决方案2】:

    可以使用 echo -e 选项启用反斜杠转义的解释。鉴于字符串可能包含特殊字符,将其用引号括起来很重要。无需使用像 sedawk 这样的 Unix 实用程序

    STRING=...
    echo -e "$STRING"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-01
      • 1970-01-01
      • 2015-07-14
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 2015-05-23
      • 2019-06-29
      相关资源
      最近更新 更多