[988] in Public-Access_Computer_Systems_Forum
those pesky capture logs
daemon@ATHENA.MIT.EDU (Dan Mahoney)
Thu Aug 13 10:56:11 1992
Date: Thu, 13 Aug 1992 09:42:25 CDT
Reply-To: Public-Access Computer Systems Forum <PACS-L%UHUPVM1.BITNET@ricevm1.rice.edu>
From: Dan Mahoney <dmahone@hal.unm.edu>
To: Multiple recipients of list PACS-L <PACS-L%UHUPVM1.BITNET@ricevm1.rice.edu>
----------------------------Original message----------------------------
Howdy,
Here are a couple of cleaning programs for those pesky capture
logs from innovative systems, I think the other person is writing
a cleaner for pc based systems, this one is for Ultrix based
systems.
First of all there is a program is from The C Answer Book
from Kernighan and Ritchiem, it deals with trimming down
those extra long lines
Hopefully one should be able to compile the program by doing a
Yourprompt % cc longlines.c
If all goes well, you have a program called a.out which you
Yourprompt % mv a.out longlines
This changes the name from a.out to longlines.
This program is a filter so to use it you must do this
Yourprompt % cat capture.log | longlines > cap.0
The program will make the long lines a reasonable length.
Cut out below and call it longlines.c then do the cc longlines.c
and then at Yourprompt % mv a.out longlines
--------------------< cut here >------------------------
#include <stdio.h>
#define MAXCOL 70
#define TABINC 8
char line[MAXCOL];
/* fold long input lines into two or more shorter lines */
main()
{ int c,pos;
pos=0;
while ((c = getchar()) !=EOF) {
line[pos] = c;
if (c == '\t')
pos = exptab(pos);
else if (c == '\n') {
printl(pos);
pos = 0;
}
else if (++pos >= MAXCOL) {
pos = findblnk(pos);
printl(pos);
pos = newpos(pos);
}} }
/*printl: print line until pos column */
printl(pos)
int pos;
{ int i;
for (i = 0; i < pos; ++i)
putchar(line[i]);
if (pos > 0)
putchar('\n');
}
/*exptab: expand tab into blanks */
int exptab(pos)
int pos;
{ line[pos] = ' ';
for (++pos; pos < MAXCOL && pos % TABINC != 0; ++pos)
line[pos] = ' ';
if (pos < MAXCOL)
return pos;
else {
printl(pos);
return 0;
} }
/*findblnk: find blanks position */
int findblnk(pos)
int pos;
{ while (pos > 0 && line[pos] != ' ')
--pos;
if (pos == 0)
return MAXCOL;
else
return pos+1;
}
/*newpos: rearrange line with new position */
int newpos(pos)
int pos;
{ int i,j;
if (pos <= 0 || pos >= MAXCOL)
return 0;
else { i = 0;
for (j = pos; j < MAXCOL; ++j) {
line[i] = line[j];
++i;
} return i;
}
}
------------------< cut here >------------------------
Cut this out below and call it iclean
then do a chmod +x iclean to make it executable
then the syntax is Yourprompt % iclean capture.log
---------< cut here >-----------
#!/bin/sh
cat $* | longlines > $*.c0
tr -d '\015' < $*.c0 | tr -d '\033' | tr -d '\017' > $*.c1
sed -f inno2.sed < $*.c1 > $*.c2
cp -f $*.c2 $*.cleaned
rm -f $*.c?
echo Output is $*.cleaned
--------< cut here >----------
Also you will need the following file that sed will use
Cut this out and call it inno2.sed, no need to make it
executable cause it just gets read and not executed.
---------< cut here > ---------
s/\[..;..H//g
s/\[..;.H//g
s/\[.;..H//g
s/\[.;.H//g
s/\[K//g
s/\[2J//g
s/\[.;.;7m//g
s/\[.;.m//g
s/\[..//g
s/\[.//g
s/qqqqqq//g
s/^ * //g
/^$/D
-------< cut here > ----------
This will trim the capture.log pretty well,
And if you want to enchance it some, here you go
After you have ran it once, look at the output, and cut out the
menu screens
like this (your screens may differ somewhat)
=================
Operated by the University
You may search for materials by any of the following:
A > AUTHOR
T > TITLE
S > SUBJECT (Library of Congress Subject Headings)
W > WORDS from titles, subjects, organizations, etc.
N > Contents (table of contents, summary, notes)
C > CALL NUMBER
B > STANDARD NUMBER (ISBN, ISSN, Music No., etc.)
R > Course RESERVES
I > Library INFORMATION
D > DISCONNECT
=================
Now using vi do the following
1) vi the file and call it additional.sed
2) do a ESC :s/^/\// #should add a / in first column on line
3) do a ESC :s/$/\/D/ # should add a /D at end of line
4) do a ESC :wq
*****CAVEAT******
If there is a / somewhere on the line between the initial /
and the ending /D sed will have problems, so delete the
inside / and everything to the right of it. Sed also
has problems if the file is too long, I think limit
is 75 lines or so,
What we are telling sed is if you see the "I > Library INFORMATION"
line, delete it. If you want to add this to the iclean program
edit the iclean file like this.
-------< iclean with enchancements >-----
cat $* | /u1/info/bin/longlines > $*.c0
tr -d '\015' < $*.c0 | tr -d '\033' | tr -d '\017' > $*.c1
sed -f inno2.sed < $*.c1 > $*.c2
sed -f additional.sed < $*.c2 > $*.c3
cp -f $*.c3 $*.clean
rm -f $*.c?
echo Output is $*.clean
---------< iclean w/ enchancements >----------
End of story, sorry to ramble, hope this helps someone
dan mahoney
centennial science and engineering library
univ of new mexico
abq nm 87131