Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 更换vi中第二行至最后一行-1_Regex_Unix_Sed_Vi - Fatal编程技术网

Regex 更换vi中第二行至最后一行-1

Regex 更换vi中第二行至最后一行-1,regex,unix,sed,vi,Regex,Unix,Sed,Vi,我试图替换sed中从第二行到最后一行的内容。但是我不能得到正确的地址 例如:在一个文件中 1 2 3 4 5 我想做: 1 2, 3, 4, 5 在vi中,它必须是这样的:2、$-1s/$/,/但是$-1不起作用。请建议。这可能适合您: seq 5 | sed '1b;$b;s/$/,/' 1 2, 3, 4, 5 你很接近。在“s”命令的末尾需要一个“g”。在vim中: :2,$-1 s/$/,/g 将完成

我试图替换sed中从第二行到最后一行的内容。但是我不能得到正确的地址

例如:在一个文件中

    1
    2
    3
    4
    5
我想做:

    1
    2,
    3,
    4,
    5

在vi中,它必须是这样的:2、$-1s/$/,/但是$-1不起作用。请建议。

这可能适合您:

seq 5 | sed '1b;$b;s/$/,/'
1
2,
3,
4,
5

你很接近。在“s”命令的末尾需要一个“g”。在vim中:

:2,$-1 s/$/,/g

将完成这件事。

对不起,这不是编程问题。投票转到superuser.com。祝你好运。@Sumit Kumar Ghosh
:2,$-1s/$/,/
工作得很好(Ubuntu 11.10上的vim 7.3.154),实际上,
:2,$-1s/$/,/
工作得很好(Ubuntu 11.10上的vim 7.3.154)-
g
是在你想进行多次替换时使用的,所以这里不需要这个。请参阅
:帮助:s_标志