用sed替换控制字符

时间:2014-02-18 10:11:50

标签: regex linux bash sed

因为我对sed(或任何其他可能适合的工具)非常不熟悉,所以我有以下问题: 我有一个包含控制字符的字符串,必须用实际函数替换。到目前为止,这些控制字符没有效果。

即:

原始字符串:

Rating..........Red\nAlert.Name......High Update Response Time\nManaged.Object..D0P~ABAP~sap00d0p_D0P_48

应该成为:

Rating..........Red
Alert.Name......High Update Response Time
Managed.Object..D0P~ABAP~sap00d0p_D0P_48

如何使用sed(或适当的工具)实现这一目标

已编辑:脚本如下:

function specChars { s=$1 echo -e "$s" }
SERVICENAME=\"$(specChars "$1")\" >> /export/home/ovolog/solman/test.log
printf "\n"
echo (specChars "$1")

1 个答案:

答案 0 :(得分:4)

没有控制字符。只需echo -e即可显示此字符串:

s='Rating..........Red\nAlert.Name......High Update Response Time\nManaged.Object..D0P~ABAP~sap00d0p_D0P_48'

echo -e "$s"
Rating..........Red
Alert.Name......High Update Response Time
Managed.Object..D0P~ABAP~sap00d0p_D0P_48