Operating System - OpenVMS
1752795 Members
5739 Online
108789 Solutions
New Discussion юеВ

Using lexical function in a dcl-command file with OpenVMS

 
Flex_2
New Member

Using lexical function in a dcl-command file with OpenVMS

Hi,

I have a script to run on my system. This script creates a text file every day. I have the following problems. How can I solve these issues in a DCL script?

1st:
I want the first and last line completely delete from this text file. The first line is empty and the last line always contains the same text string.

Second:
For all other rows (the number of rows varies daily) I would like to delete any spaces.

I hope my English is to be understood.

Regards,

Rick
10 REPLIES 10
P Muralidhar Kini
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

Hi Rick,

Welcome to the ITRC forum.

Here is one way of doing this. This method involves reading the entire file
contents and then doing the modifications required on every line.
Hence may not be the best way of achieving the desired result.

Lets say you have created a file TEMP.TXT.

Then you need to open and read all the lines of the file TEMP.TXT.
...
OPEN FILEPTR "TEMP.TXT"
READ/END_OF_FILE=END_LOOP FILEPTR Line
...

Copy all the lines of this file to a new file.
During this,
- Dont copy
- first line (first read operation)
- the last line which has a known string.
Use F$MATCH_WILD lexical to detect the pattern
- Remove spaces from other lines
Use F$EDIT lexical with "TRIM"/"COMPRESS"/"COLLAPSE " based on your requirement.

Hope this helps.

Regards,
Murali
Let There Be Rock - AC/DC
Hein van den Heuvel
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

Do you have PERL or AWK at your disposal?
This is a trivial exercise in those languages.
See example below.
Real OpenVMS folks would write an TPU/EDT macro for this.

hth,
Hein


$ cre tmp.txt
first line
secone line with spaces
third line with leading and trailing space
last line
$
$ perl -ne "next if 1==$.; last if eof; s/[ \t]//g; print" tmp.txt > tmp.tmp
$
$ type tmp.tmp
seconelinewithspaces
thirdlinewithleadingandtrailingspace
$

-ne ## loop over input, no auto print
next if 1==$.; ## if the line number is 1
last if eof; ## if an end of file next
s/[ \t]//g; ## substitute

print ## the default variable $_ ... if it gets here

> tmp.tmp ## redirect output

Hein van den Heuvel
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

lunchbreak...

The perl I showed stripped tabs (\t) and spaces. If you just are conderned with spaced, use:

s/ //g;

If you insist on DCL, try script below using
it as: $ @strip/out=new.txt old.txt

---- strip.com --------------------
$ if p1.eqs."" then exit 16
$ open/read/erro=oops file 'p1
$ read file record ! blow aways first line
$ read file record ! read and edit second record before loop
$ last = f$edit(record,"COLLAPSE")
$
$loop:
$ read/erro=oops/end=done file record
$ write sys$output last
$ last = f$edit(record,"COLLAPSE")
$ goto loop
$
$done:
$ close/nolog file
$oops:
$ exit .NOT.%x10000000 .AND. '$status

Jan van den Ende
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

Rick,

I think I would make an EDT command file.

$ cre MODIFY.EDT
dl
s/ //wh
.end
-1
dl
$

Explanation:
d - delete line
s/ //wh - substitute string between first and second separator ( I prefer "/", unless I need to do something with /'s, in which case I use "?" or "|", matter of taste ). That string in your question is one space.
Replace it by the string between second an third separator, in you question, nothing.
Then wh - specifies to do this over the WHole file.
. end - move to end of file
- 1 - up one line
dl - delete line

Now invoke EDT with this specification.

$ EDITT/EDT/COMMAND=MODIFY.EDT file-to-be-modified.

Save MODIFY.EDT and use as often as needed.

Note EDITT with an extra T, to avoid any EDIT symbol.

hth

Proost.

Have one on me.

jpe

Don't rust yours pelled jacker to fine doll missed aches.
John Gillings
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

Rick,

As others have posted, you can write another script in whatever language you like best to edit the text file. Personally I'd choose Perl for this particular task.

[aside... hey jpe, no disrespect intended, but EDT was made obsolete in 1983 with the release of VMS V4.0, is it really appropriate to expose new people to such an old, klunky and seriously limited utility?]

Wouldn't it make more sense to go back to the script that's creating the file, and modify it to output the text file in the format you really want?

Or, look at the reasons you want the file edited, perhaps it's for input into another script. Can that be modified to apply the edits as it runs?

The point here is you can always "fix" something by adding yet another step in a process, BUT most of the time that adds extra dependencies and extra opportunities for things to go wrong, to say nothing of additional resources used in re-processing data.

In general I know I'm going in the right direction when I'm REMOVING code and simplifying processes.
A crucible of informative mistakes
Jan van den Ende
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

Re John:

>>>
[aside... hey jpe, no disrespect intended, but EDT was made obsolete in 1983 with the release of VMS V4.0, is it really appropriate to expose new people to such an old, klunky and seriously limited utility?]
<<<

John, I know. Interactively I use TPU. But I have always found the non-interactive use of TPU "a bit" clumsy & untidy, where EDT worked/works just fine. (And for really complex batch editting I have been known to go back even further to SLUM (not even sure about that name anymore) or TECO, but then I require the manual.

But for not-too-complex batch editting, like this, EDT is still my choice. Despite the limits (of which the max line length has bitten me most often). Shows my age well I guess.

Proost.

Have one on me.

jpe

Don't rust yours pelled jacker to fine doll missed aches.
Flex_2
New Member

Re: Using lexical function in a dcl-command file with OpenVMS

Hi,

thank you first for the answers. I will try the tips equal times.

An addition: Some of the answers related to other languages. However, I have a closed system. That means I can work only on the OpenVMS machine with DCL.

Greeting

Rick
Hein van den Heuvel
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

>> An addition: Some of the answers related to other languages. However, I have a closed system. That means I can work only on the OpenVMS machine with DCL.


The system is open.
The minds are closed.

Regards,
Hein.


Ian Miller.
Honored Contributor

Re: Using lexical function in a dcl-command file with OpenVMS

but noone mentioned SUMSLP :-)

http://h71000.www7.hp.com/doc/73final/documentation/pdf/OVMS_SUMSLP_UTIL.pdf
____________________
Purely Personal Opinion