• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

delete lines from file

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

Thanks
0
basirana
Asked:
basirana
2 Solutions
 
sardiskanCommented:
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.
0
 
wareb73Commented:
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
0
 
amit_gCommented:
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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
jazzIIIloveCommented:
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
:wq

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.
0
 
martin_2110Commented:
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

0
 
basiranaAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now