ex again
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > ex again




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    ex again  
tony


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:00 AM

Hi.  A couple months ago I posted this question but didn't come up
wuith a complete solution.

"Can I use ex to find a pattern and NOT print that line and the
previous x number of lines? "

Several method of printing the previous lines were offerred but none
were given to NOT print the previous 'x' number of lines.

More details:  I have a large text file (~70 megs).  There are 'pages'
in the file of 60 records each.  The pattern I can search for is on
the 60th line.  There may be 1 or many pages in a row that I don't
want.

Any suggestions are welcome,
thanks





[ Post a follow-up to this message ]



    Re: ex again  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-07-07 01:00 AM

2007-01-03, 12:04(-04), tony:
> Hi.  A couple months ago I posted this question but didn't come up
> wuith a complete solution.
>
> "Can I use ex to find a pattern and NOT print that line and the
> previous x number of lines? "

ex is text editor. It is therefore poorly suited to "print"
things.

> Several method of printing the previous lines were offerred but none
> were given to NOT print the previous 'x' number of lines.
>
> More details:  I have a large text file (~70 megs).  There are 'pages'
> in the file of 60 records each.  The pattern I can search for is on
> the 60th line.  There may be 1 or many pages in a row that I don't
> want.
[...]

awk '
NR % 60 == 0 {
if (!/pattern/) {
printf "%s", page
}
page = ""
}
{page = page $0 "\n"}'

Every 60 line, print the current /page/ (60 previous lines) only
if the current line doesn't match the /pattern/

--
Stéphane





[ Post a follow-up to this message ]



    Re: ex again  
Kenny McCormack


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-08-07 12:16 AM

In article <slrnepnlgc.aid.stephane.chazelas@spam.is.invalid>,
Stephane CHAZELAS  <this.address@is.invalid> wrote:
>2007-01-03, 12:04(-04), tony: 
>
>ex is text editor. It is therefore poorly suited to "print"
>things.

Yes, in fact my first reaction to this post was that it is real easy to
write a script that does NOT (emphasis OP's) do X, for any value of X.






[ Post a follow-up to this message ]



    Re: ex again  
John Savage


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-26-07 12:20 PM

tony <bigtoehere@hotmail.com> writes:
>Hi.  A couple months ago I posted this question but didn't come up
>wuith a complete solution.
>
>"Can I use ex to find a pattern and NOT print that line and the
>previous x number of lines? "
>
>Several method of printing the previous lines were offerred but none
>were given to NOT print the previous 'x' number of lines.
>
>More details:  I have a large text file (~70 megs).  There are 'pages'
>in the file of 60 records each.  The pattern I can search for is on
>the 60th line.  There may be 1 or many pages in a row that I don't
>want.

I'll echo others in saying that ex is probably not the tool for the job,
for a number of reasons. Accepting this, then in the absence of unstated
confounding specs the task seems straightforward.

To not print the preceding x lines, simple delete them from the editor's
buffered copy of the database file before saving what's left to a new
file and then print that file. :-)

E.g., one by one look for a line containing "page n" and if that line
also contains the word "debit" delete that line and the preceding
60 lines. Print what's then left. Something like:

%g/page [0-9].*debit/-60;//d
w !lpr
q!

It might be wise to ensure your valuable text file is write protected
before letting any ex script loose on it.
--
John Savage                   (my news address is not valid for email)





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:50 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register