How do you delete all lines that begin with “string” in unix sh?

柔情痞子 提交于 2019-11-28 19:15:29
grep -v '^string' yourfile.txt > stripped.txt

To do it in place, if your sed supports the -i option, you can do:

sed -i '/^string/d' input-file

sed and grep in your answers are missing their friend awk:

awk '!/^string/' inputfile > resultfile

You can use Vim in Ex mode:

ex -sc g/^string/d -cx file
  1. g select all matching lines

  2. d delete

  3. x save and close

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!