LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2008, 11:56 PM   #1
aliyesami
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Rep: Reputation: 0
sed and multiline delete


there was an old thread with Pixellany posting a very nice solution for deleting one line above the pattern line as follows :
" sed '/^$/d' 2line |sed -n 'h;n;H;g;/Que/!p' "
Since the post is old iam not sure if he or someone else will look there so I am posting my question here also since i need this problem solved urgently hopefully sysadmin will forgive me for double posting

I want a line above and below the line starting with %CLI-E deleted including the pattern line itself if possible.

so for example I want these the following lines


$CHECKSUM $1$DGA243:[ORACLE.PATRON]FGAG01.DBF;1
%CLI-E-OPENIN, error opening $1$DGA243:[ORACLE.PATRON]FGAG01.DBF;1
-RMS-E-FLK, file currently locked by another user
$CHECKSUM $1$DGA1043:[ORACLE.PATRON]TSTST01.DBF;1
%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF
-RMS-E-FLK, file currently locked by another user
$CHECKSUM $1$DGA441:[ORACLE.PATRON]AFARG01.DBF;1
CHECKSUM 12142131


reduced to

%CLI-E-OPENIN, error opening $1$DGA1043:[ORACLE]TSTST01.DBF
%CLI-E-OPENIN, error opening $1$DGA243:[ORACLE.PATRON]FGAG01.DBF;1
$CHECKSUM $1$DGA441:[ORACLE.PATRON]AFARG01.DBF;1
CHECKSUM 12142131

or preferably this

$CHECKSUM $1$DGA441:[ORACLE.PATRON]AFARG01.DBF;1
CHECKSUM 12142131


thanks for your help
Sami
Florida
 
Old 06-27-2008, 12:38 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Your results and data suggests that all you want are lines that start with "$CHECKSUM" and "CHECKSUM". Is this correct?

Sed is not the best tool for the job.
 
Old 06-27-2008, 08:43 AM   #3
aliyesami
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Original Poster
Rep: Reputation: 0
no its not correct ...I want everything else in file remain other than the two lines above and below the pattern line as I stated in the example.
 
Old 06-27-2008, 02:03 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Code:
$ cat del.pl
#!/usr/bin/perl 

undef $/;
$_ = <>;

s/^.*?\n^%CLI-E.*?\n^.*?\n//gms ;

print "$_";
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
delete lines with sed LuciusHunt Programming 1 04-19-2008 02:40 PM
Delete a line using sed kushalkoolwal Programming 2 09-29-2007 07:25 PM
using sed to delete line to the right khairilthegreat Linux - Newbie 5 07-28-2007 02:10 PM
substituting multiline string in sed rohit2983 Programming 3 01-31-2007 09:00 AM
cannot delete certain files with sed ganninu Linux - General 6 12-10-2003 03:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration