delete lines from file

Posted on 2009-12-28
Last Modified: 2012-05-08
I have a spool file that is accessed in shell script.
I have following patterns in spool file. If I find this patterns how can I delete the lines from the file and delete them?

ORA-02068: following severe error from
ORA-01033: ORACLE initialization or shutdown in progress

Question by:basirana
    LVL 5

    Expert Comment

    If you use vim on the filename you can delete those lines using "dd".

    > vi filename

    move your cursor to the beginning of the lines in question, then press the d key twice. That will delete the entire line. Pressing the d key twice again will delete the next line.

    When you are done, press the colon key which will show up in the bottom left hand of the screen, then type x and hit might prompt you to save the file.
    LVL 4

    Accepted Solution

    sed -e /pattern/d File name.

    Exapmle from above,

    sed -i /following severe error from/d filename
    sed -i /ORACLE initialization or shutdown in progress/d filename
    LVL 58

    Assisted Solution

    sed -i -e '/ORA-02068: following severe error from/ d' -e '/ORA-01033: ORACLE initialization or shutdown in progress/ d' TheFileName

    You could also shorten it if the pattern is not repeated anywhere else in the file.

    sed -i -e '/ORA-02068:/ d' -e '/ORA-01033:/ d' TheFileName
    LVL 12

    Expert Comment

    Open the file with vi editor, that you can downloaded as vim for Windows and vi in your linux if you are using it.
    Then in Windows right click on the file and select vim, or in Linux, in console open the file as vi filename then:

    In vi, first press <esc>, esc is for dropping to command mode as below:

    :g/ORA-02068: following severe error from /d
    :g/ORA-01033: ORACLE initialization or shutdown in progress /d

    g searches for the pattern, d deletes it, w saves the file, q quits the program.
    If you are not sure what mode you are in, simply press <esc>, this will drop you to command mode. The other mode is insert mode, that you can insert text into your file by pressing <i> character.

    Best regards.
    LVL 7

    Expert Comment

    I like this better.
    egrep -v 'ORA-02068: following severe error from|ORA-01033: ORACLE initialization or shutdown in progress' /path/to/file > /path/to/file.tmp ; mv /path/to/file.tmp /path/to/file

    Open in new window


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
    It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now