我刚接触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 //
我希望我的脚本查看第一个字符是否为 - (忽略空格/制表符),如果是,则添加空格和//
答案 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 //