Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How's pop11 for such little tasks ?

2 views
Skip to first unread message

problems@gmail

unread,
Apr 20, 2008, 8:18:26 AM4/20/08
to
I need to often delete repeated patterns of consecutive
lines in text files, which patterns start with a line of
partially known contents, and have 2 to 4 further lines,
and end with a line of partially known content.

eg.
line1
...
asd OpenBrkt
wre bad stuff
54 badstuff
fdakj CloseBrkt
goodline n
kjkk good line
...

Where I'd need to delete from line:
asd OpenBrkt
to line
fdakj CloseBrkt
inclusively.

Pseudo code could be:
ReadIn byLine from SrcFile till EOF.
IF currentLine contains "openBraket"
THEN Initialise 0 -> SkipCounter
REPEAT ReadIn; INC(SkipCounter)
UNTIL( SkipCounter < 4)
AND (currentLine notContains "CloseBrkt")
ELSE accept currentLine {eg. by not deleting}

Thanks,

== Chris Glur.

Aaron Sloman

unread,
Apr 20, 2008, 10:26:19 AM4/20/08
to
Chris Glur wrote:

> Date: Sun, 20 Apr 2008 07:18:26 -0500

Here's a first draft

I think the first procedure handles all cases as described
but have not done enough testing to be sure.

The second procedure defines an ENTER command to read three strings,
separated by spaces, from the command line, and then gives them to
the first procedure.

define veddelrange(goodline, OpenBrkt, Closebrkt);
;;; all three arguments are strings.

;;; find the goodline
vedlocate(goodline);
;;; locate beginning of range to be deleted
vedlocate(OpenBrkt);
;;; deleted up to but not including closer. See REF ved_ds
veddo('ds ' <> Closebrkt);
enddefine;

;;; define a command to invoke the above

;;; ENTER delrange string1 string2 string3
define ved_delrange;
;;; expect
lvars args = sysparse_string(vedargument);
unless listlength(args) == 3 then
vederror('Three args required for ENTER delrange');
endunless;
veddelrange(explode(args));

enddefine;

More complexity is needed to allow the strings on the command line
to include spaces. This could be done by specifying a leading
delimiter character to be given as an additional argument to be
handed to veddelrange, which would then use sys_parse_string with a
'sepchar' instead of just using sys_parse_string to decompose the
argument line. It would take a few lines more code.
(See REF STRINGS)

Note, the portion of text removed by ved_ds (i.e. ENTER ds)
can be reinserted anywhere, before the next call of ved_ds using the
command
ENTER splice

(or ved_splice). It will be inserted after Ved's text cursor
location.

Aaron
http://www.cs.bham.ac.uk/~axs/

0 new messages