[Webinar] Learn how to a build a cloud-first strategyRegister Now


delete lines from file

Posted on 2009-12-28
Medium Priority
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

Expert Comment

ID: 26133689
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 enter...it might prompt you to save the file.

Accepted Solution

wareb73 earned 1000 total points
ID: 26133699
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

amit_g earned 1000 total points
ID: 26133702
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

LVL 12

Expert Comment

ID: 26133734
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.

Expert Comment

ID: 26133757
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

ID: 31670541

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

864 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