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

前端 未结 4 1269
没有蜡笔的小新
没有蜡笔的小新 2020-12-13 19:33

How do you delete all lines in a file that begin with \"string\" in sh? I was thinking about using the sed command.

相关标签:
4条回答
  • 2020-12-13 19:39

    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

    0 讨论(0)
  • 2020-12-13 19:42

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

    awk '!/^string/' inputfile > resultfile
    
    0 讨论(0)
  • 2020-12-13 19:45

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

    sed -i '/^string/d' input-file
    
    0 讨论(0)
  • 2020-12-13 19:59
    grep -v '^string' yourfile.txt > stripped.txt
    
    0 讨论(0)
提交回复
热议问题