在文本文件中添加特殊字符后的空格

时间:2014-09-01 02:18:55

标签: bash awk sed

我需要帮助分隔文件中的多个if语句。

变化:

 [[ "$File1" == "Word1" ]] || [[ "$File1" == "Word2" ]] ||

为:

 [[ "$File1" == "Word1" ]] ||
 [[ "$File1" == "Word2" ]] ||

我在网上找到的所有内容都不适用于像||这样的特殊字符 我想我需要使用awk或sed,但我不确定如何让它工作。

2 个答案:

答案 0 :(得分:2)

$ sed 's@|| @||\n@g' input
[[ "$File1" == "Word1" ]] ||
[[ "$File1" == "Word2" ]] ||

答案 1 :(得分:0)

您也可以使用awk

awk '{sub(/\|\| /,"&"RS)}1' file

echo "[[ "$File1" == "Word1" ]] || [[ "$File1" == "Word2" ]] ||" | awk '{sub(/\|\| /,"&"RS)}1'
[[  == Word1 ]] ||
[[  == Word2 ]] ||