Unix Shell - ex again

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2007 > ex again





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author ex again
tony

2007-01-06, 8:00 pm

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
Stephane CHAZELAS

2007-01-06, 8:00 pm

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
Kenny McCormack

2007-01-07, 7:16 pm

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.

John Savage

2007-01-26, 7:20 am

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)
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com