Computing.Net > Forums > OpenVMS > How to Search a Keyword in a File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to Search a Keyword in a File

Reply to Message Icon

Name: ABC
Date: August 28, 2006 at 03:15:35 Pacific
OS: DEC Open VMS 6.2
CPU/Ram: .
Product: .
Comment:

Hi am new to VMS platform
I have one file which conatins "EOF" as a Keyword at the end of File.
e.g aaaa
ansnans
"EOF"
If I found the "EOF" word then do some process.
else throw an error message.
Is anybody will help me.

Sanjay.



Sponsored Link
Ads by Google

Response Number 1
Name: KellyS
Date: August 28, 2006 at 13:24:23 Pacific
Reply:

Welcome to OpenVMS.

The method you need for this search depends on whether you want to do this from in a command, a command file (or script), or a program. I'll assume a command file.

One way is to use the DCL commands OPEN, READ, and CLOSE to read each record in the file. For instance, write a command file called EOF.COM (watch out for word-wrapping):

$ on error then goto exit
$ open myfile 'p1'
$ myrecord = " "
$ doread:
$ lastrecord = myrecord
$ read myfile myrecord /end_of_file=done
$ goto doread
$ done:
$ if (f$locate ("EXIT", lastrecord) .lt. f$length(lastrecord))
$ then
$ ! do some processing here
$ else
$ write sys$error "No keyword found"
$ endif
$ exit:
$ close myfile

then execute this command file and pass it the name of the data file:

$ @eof data_file.dat

If you just want to check the file manually, you can use the TYPE command:

$ type data_file.dat /tail=1

You should probably read the manual on the command language, DCL, at http://h71000.www7.hp.com/doc/83FINAL/9996/9996PRO.HTML
It is just one manual in an extensive doc set. The HELP command is also very useful. For the "f$" functions, enter HELP LEXICAL.

Hope this helps,
Kelly


0

Response Number 2
Name: Waxinator
Date: October 10, 2006 at 11:49:37 Pacific
Reply:

...or...
$ search datafile.dat "EOF" /nooutput/nowarning
$ if $status .eqs. "%X08D78053" then goto no_eof
$ ! execute commands for a correct datafile.
$ exit
$
$ no_eof:
$ ! execute commands indicating failing EOF test
$ exit


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: How to Search a Keyword in a File

How to edit a binary file ? www.computing.net/answers/openvms/how-to-edit-a-binary-file-/191.html

to write system errors into a file www.computing.net/answers/openvms/to-write-system-errors-into-a-file/324.html

To split a string with a space www.computing.net/answers/openvms/to-split-a-string-with-a-space/321.html