Operating System - OpenVMS
1752785 Members
6279 Online
108789 Solutions
New Discussion юеВ

Re: Diplaying TOP 10 messages of a file

 
SOLVED
Go to solution
Sk Noorul  Hassan
Regular Advisor

Diplaying TOP 10 messages of a file

Hi,

I need to display first 10 messages from a file that contains more than 150 messages which is created by running an executable in VMS. I want to write a dcl script for the user, who on click will get only first 10 messages on his screen.

Pls suggest.
15 REPLIES 15
Steven Schweda
Honored Contributor

Re: Diplaying TOP 10 messages of a file

What's a "message"? "Click"?

HELP OPEN
HELP IF
HELP READ
HELP WRITE
HELP GOTO
HELP CLOSE

A UNIX "head" program might also be useful.
Heinz W Genhart
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Here a small hack to do what You want to do

$ ON CONTROL_Y THEN GOTO clean_up
$ max_lines = 10
$ IF P1 .EQS. "" THEN INQUIRE P1 "Enter File Name "
$ IF F$SEARCH(P1) .EQS. ""
$ THEN
$ WRITE SYS$OUTPUT "File ''P1' not found "
$ GOTO clean_up
$ ENDIF
$ OPEN/READ in 'P1'
$r_loop:
$ READ/END_OF_FILE=end_file in record
$ WRITE SYS$OUTPUT record
$ max_lines = max_lines -1
$ IF max_lines .GT. 0 THEN GOTO r_loop
$!
$end_file:
$ CLOSE in
$clean_up:
$ IF F$TRNLNM("in") .NES. "" THEN CLOSE IN
$ EXIT

Hope that helps
Jan van den Ende
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sk,

What VMS version?
Beginning in V7.3-2 SEARCH has some real nice new features.
$ SEARCH "something crazy"/MATCH=NOR/LIMIT=10
will do what you are asking.

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Hein van den Heuvel
Honored Contributor

Re: Diplaying TOP 10 messages of a file


Do you mean the first lines in the file, like the Unix 'head' command?

If you have perl installed, that solves as:

perl -pe "last if $. > 10" x.c

explanation:
-p = loop through input reading into variable $_ printing $_ at block end.
-e = program text coming up

last = exit loop
$. = current line in input
> 10 = your top choice


Using a standard VMS tool like edt, you could (pre-)create a command sequence:

$ create top_ten.edt
set nonumbers
type 1:10
quit
$
$edit/edit/command=top_ten.edt your-data


Or do you mean a sort of statistics function, finding the messages which occur most often? Then the solution in perl gets trickier

perl -ne "$x{$_}++; END {foreach (sort {$x{$b}<=>$x{$a}} keys %x) {last if ++$i > 10; print ""$x{$_} $_"" }}" your-data

-n = loop through input, but do not print
-e = program
$x{$_}++ = (create and) increment element with key $_ in array %x
END = do this when input exhausted
keys %x = all keys from array, in a list
sort = sort, normally by key value, but here we provide a sort routine comparing not the key values, but the pointed to array values.
foreach = loop through list setting $_ each time
last if ++$i > 10 = your output cut-off choice
print = finally... what we came to do.


Cheers,
Hein.
Hein van den Heuvel
Honored Contributor

Re: Diplaying TOP 10 messages of a file

[Some corrections.. I pasted the wrong buffer..]

>> perl -pe "last if $. > 10" x.c

The x.c was the text I tested with.
To be replaced by 'your_data'.


>> $edit/edit/command=top_ten.edt your-data

That was of course supposed to be: EDIT/EDT
Some folks will need EDITXX/EDT, or just EDT to deal with local defintions for EDIT or EDT.

Hein.
Arch_Muthiah
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Noorul,

There is one more good VMS freeware (Hunter Goatley's) 'extract' utlity.

You can download and install it within a minute from http://vms.process.com/scripts/fileserv/fileserv.com?EXTRACT

It has so many facilities such as selecting any number of records from the biginning, middle, or end of one file or more files and optionally performs various modifications before displaying on the screen.

Syntax and example

$ extract /record=([START=m,END=n,COUNT=k]) file1, file2...
$ extract /record=(start=5, count=15) file1
---> displays 10 lines starting from 5th line.

$ extract /head=k file1
$ extract /head=10 file1
--->displays top 10 lines

$ extract /tail=k file1
$ extract /tail=10 files
---> displays bottom 10 lines

We are using this for long time. And there few more freeware utilities avalible for VMS, but I feel this is very easy.

Archunan
Regards
Archie
John Gillings
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sk,

As others have said, it depends on what you mean by "message". If you mean "line" the most obvious is the V7.3-2 and higher SEARCH command. You don't need to use /NOR as suggested by Jan, just search for a null string:

$ SEARCH file ""/LIMIT=10

You can combine this with /SKIP to select any range of the file you like. For example, suppose you wanted 10 lines starting at line 25:

$ SEARCH file ""/SKIP=25/LIMIT=10

If your messages contain a specific string, search for that, again with /LIMIT

Another option is TYPE/PAGE combined with SET TERM/PAGE:

$ SET TERMINAL/PAGE=10
$ TYPE/PAGE file

Of course, this leaves your terminal at 10 pages, which probably isn't a good idea! Save and restore like this:

$ p=F$GETDVI("SYS$COMMAND","TT_PAGE")
$ SET TERMINAL/PAGE=10
$ TYPE/PAGE file
$ SET TERMINAL/PAGE='p'

Your users will need to hit ^Z to exit from the display, or can hit RETURN or any other commands for TYPE/PAGE.

Less likely to be useful, but worth knowing about is DUMP/RECORD=(START:s,COUNT:c)

This dumps "c" records starting at record "s" (0 based), however, the output probably isn't what you're looking for.
A crucible of informative mistakes
Sk Noorul  Hassan
Regular Advisor

Re: Diplaying TOP 10 messages of a file

Hi,

Thanks a lot I could complete the job.
Sk Noorul  Hassan
Regular Advisor

Re: Diplaying TOP 10 messages of a file

Hi all,
MY VMS version is 7.1, so search command as suggested by john is not working. It is also not possible to load any additional freeware as suggested.

I have completed the job now,

Heinz,
Is it possible to take the final 10 messages to a file instead of displaying it on screen, so that I cam mail that file to end user. Pls if u can write few lines as before it will help me.