How to add vi command in shell script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyankapendkar
    New Member
    • Apr 2011
    • 9

    How to add vi command in shell script

    Hi,

    I need to delete all the lines which does not contain the "error" word in a file.
    so, in vi, I would use
    :v/error/d and then save the file.

    How can I achieve this in command line?

    Thanks in advance
  • mac11
    Contributor
    • Apr 2007
    • 256

    #2
    I'd use grep

    This will print all the "error" lines to stdout (assuming your file is called "filename")
    Code:
    grep error filename
    you can redirect if you want it to go to a file

    To replace the file in place you can also use sed
    Code:
    sed -ie '/error/!d' filename
    Last edited by mac11; Apr 27 '11, 05:42 PM. Reason: add sed

    Comment

    Working...