Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

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
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.
Jan van den Ende
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sk,

on your VMS version, you are practically restricted to:

$ TYPE /TAIL=<#-of-lines> /OUT=SYS$LOGIN:TAILTYPE.TMP
$ MAIL SYS$LOGIN:TAILTYPE.TMP
$ DELETE SYS$LOGIN:TAILTYPE.TMP;*

hth

Proost.

Have one on me.

jpe

Don't rust yours pelled jacker to fine doll missed aches.
Heinz W Genhart
Honored Contributor
Solution

Re: Diplaying TOP 10 messages of a file

Hi

I wrote 2 versions of a small hack. First example selects the first ten lines of a given file and sends it to a mail address. In both examples You must substitute the mail adress (xy) with Your own address.

$! Copies first 10 Lines of a file into a temporary file and sends this file to mail_address
$!
$ ON CONTROL_Y THEN GOTO clean_up
$ unique_filename = F$UNIQUE()
$ mail_address = "xy"
$ 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'
$ OPEN/WRITE out 'unique_filename'.dat
$r_loop:
$ READ/END_OF_FILE=end_file in record
$ WRITE out record
$ max_lines = max_lines -1
$ IF max_lines .GT. 0 THEN GOTO r_loop
$!
$end_file:
$ CLOSE in
$ CLOSE out
$ MAIL/SUBJECT=test 'unique_filename'.dat 'mail_address'
$clean_up:
$ IF F$TRNLNM("in") .NES. "" THEN CLOSE in
$ IF F$TRNLNM("out") .NES. "" THEN CLOSE out
$ DELETE 'unique_filename'.dat;*
$ EXIT


Second example writes the 10 last lines of a file into a temporary file and sends it by email

$! Creates a temporary file which contains the last ten lines of a given file. Se
$! sends the temporary file by mail
$!
$ ON CONTROL_Y THEN GOTO clean_up
$ mail_address = "xy"
$ IF P1 .EQS. "" THEN INQUIRE P1 "Enter Filename "
$ IF F$SEARCH(P1) .EQS. ""
$ THEN
$ WRITE SYS$OUTPUT "File ''P1' not found "
$ GOTO clean_up
$ ENDIF
$ unique_filename = F$UNIQUE()
$ TYP/TAIL=10 'P1'/OUT='unique_filename'.dat
$ MAIL/SUBJECT=test 'unique_filename'.dat 'mail_address'
$clean_up:
$ IF F$SEARCH("''unique_filename'.dat") .NES. "" THEN DELETE 'unique_filename'.dat;*

Hope that helps.

Heinz
Jan van den Ende
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Heinz,

look at his previous post: he is at VMS 7.1, so no F$UNIQUE available!

Proost.

Have one on me.

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

Re: Diplaying TOP 10 messages of a file

Sk,

from your Forum Profile:


I have assigned points to 63 of 140 responses to my questions.

Some of those are rather old.

Maybe you can find some time to do some assigning?

http://forums1.itrc.hp.com/service/forums/helptips.do?#33

Mind, I do NOT say you necessarily need to give lots of points. It is fully up to _YOU_ to decide how many. If you consider an answer is not deserving any points, you can also assign 0 ( = zero ) points, and then that answer will no longer be counted as unassigned.
Consider, that every poster took at least the trouble of posting for you!

To easily find your streams with unassigned points, click your own name somewhere.
This will bring up your profile.
Near the bottom of that page, under the caption â My Question(s)â you will find â questions or topics with unassigned points â Clicking that will give all, and only, your questions that still have unassigned postings.

Thanks on behalf of your Forum colleagues.

PS. â nothing personal in this. I try to post it to everyone with this kind of assignment ratio in this forum. If you have received a posting like this before â please do not take offence â none is intended!

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Heinz W Genhart
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sorry, I did not see what VMS Version he uses.

On vms 7.1 just change the line

unique_filename = F$UNIQUE()

to

unique_filename ="temp_file_''F$GETJPI("","PID")'"

That will solve the problem with the missing F$UNIQUE Lexical
Hein van den Heuvel
Honored Contributor

Re: Diplaying TOP 10 messages of a file


If your system supports the PIPE command you don't need an intermediate file:

$pipe type/tail=10 more_test.tmp | mail/subj="testing" sys$pipe hein


Unfortunately this TYPE/TAIL fails on STM_LF files with:
-SYSTEM-E-UNSUPPORTED, unsupported operation or function
-RMS-F-ORG, invalid file organization value

That's really silly because it is trivial to implement, but there you have it.
The workaround is to use an intermediate file, but then we're back to having to name that. (And no, $type/page does not work on a pipe :-( ).

In the thinking outside the box solutions, I thought the following might work:

$ i = 0
$open/read x test.tmp
$open/read y test.tmp
$loop1:
$read x x
$i = i + 1
$if i.lt.10 then goto loop1
$
$loop2:
$read/end=send_mail x x
$read y y
$goto loop2
$
$send_mail:
$mail/subj="last 10" y hein
$!type y
$close x
$close y


Well... it works for $type, but not for $mail ?!

Hein.