在一行代码中查找特定的Char,忽略SED中的空格

时间:2015-02-02 00:23:01

标签: unix sed

我刚接触SED,我一直在四处寻找答案!我几乎拥有它,但无法弄明白。

____= a tab or space  

示例文字:

This is sample text - hello.   
______-this is what I want the script to detect only  
Not the - in this one   
______-Just this one 

我的脚本

/[^tab]\+-/ {  
s/$/ \\\\/  
}

输出

This is sample text - hello. //  
____-this is what I want the script to detect only //  
Not the - in this one //  
____-Just this one //  

所需输出

This is sample text - hello.  
____-this is what I want the script to detect only //  
Not the - in this one  
____-Just this one //  

我希望我的脚本查看第一个字符是否为 - (忽略空格/制表符),如果是,则添加空格和//

1 个答案:

答案 0 :(得分:1)

通过sed,

$ sed '/[^[:blank:]]\+-/s/$/ \/\//' file
This is sample text - hello.
______-this is what I want the script to detect only //
Not the - in this one
______-Just this one //