给定以下文件
$ cat a.txt
The quick brown fox jumps over the lazy dog
我可以使用 sed
轻松删除第一部分
$ sed 's/.*fox//' a.txt
jumps over the lazy dog
我试图巧妙地使用 D
选项
D Delete up to the first embedded newline in the pattern space.
例子
$ sed 's/fox/\n/; D' a.txt
但是这没有输出。是否可以使用 D
选项通过 sed
删除一行的第一部分,这与我尝试过的类似?
如果 fox
之前的部分比之后的部分短,这会起作用。
$ sed 's/fox/\r/' a.txt
jumps over the lazy dog
最佳答案
一种方法:
sed '/fox/{s/fox/\n/;D}' input
关于bash - 删除行的第一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15062361/