tejas shah
tejas shah

Reputation: 11

Deleting first four lines in a file in openvms ---> Dcl scripting

Suppose i have a file name Trialcr.txt

PAR875:FXOV003506A_02> typ trialcr.txt

Classes in CMS Library DISK_FXOCMS:[fxo.CMS.LIBS.FXO_LIV.SRC]

FXO_CR012123 "FXO_CR1232 : FXOME-sfsfsfsf dasdad "
    ABC.COM 2
    PQ.BSQL 1

I want to delete the first 4 lines and keep only

ABC.com and PQ.com

Want this to be done dynamically.

Can anyone suggest someway

Upvotes: 0

Views: 1143

Answers (3)

Hein
Hein

Reputation: 1463

I like to use PERL or AWK for these kind of tasks.

$ perl -ne "print if $. > 4" TRIALCR.TXT  [ > x.x ]
$
$ gawk /com="NR>4" TRIALCR.TXT  [/output=x.x]

Searching for a known to be there string as per user2116290 is fine also. With RECENT OpenVMS versions, for this specific case consider searching for a non-match on a non-existing string and skipping 4 lines. (Search for "" does not match empty lines)

$ search TRIALCR.TXT;1 "@#$%" /match=nor /skip=4

Jim has a fine answer in his script. There is a nice simplification possible, if you realize how process permanent files work. Have DCL swallow the first 4 lines, then copy the rest to a target file.

$ close/nolog input
$ open/read/error=error input trialcr.txt
$ read/end=error/error=error input junk
$ read/end=error/error=error input junk
$ read/end=error/error=error input junk
$ read/end=error/error=error input junk
$ COPY input trialcr.txt
$ close input
$exit:
$ exit
$error:
$ write sys$output "Unexpected error: " + f$message ($status)
$ goto exit

Enjoy, Hein

Upvotes: 2

user2116290
user2116290

Reputation: 1072

Suppose i have a file name Trialcr.txt

which looks like the output of a CMS SHOW CLASS/CONTENT for class FXO_CR012123. Given the layout for the output of such a command (four blanks in front of the element name) in your example a simple

$ search Trialcr.txt "    "

should print the wanted lines. However, in general, there may be as many as four blanks between the class name and its description. To be safe a one-liner like

$ pipe search Trialcr.txt "    " |search sys$pipe FXO_CR012123/match=nand

should produce the expected result for all class names. Redirecting the output will write the wanted lines (which include the version numbers) into a file.

Upvotes: 0

Jim
Jim

Reputation: 83

$ close/nolog input
$ close/nolog temp
$ temp = f$unique () + ".tmp"
$ open/read/error=error input trialcr.txt
$ open/write/error=error temp 'temp'
$ read/end=error/error=error input junk
$ read/end=error/error=error input junk
$ read/end=error/error=error input junk
$ read/end=error/error=error input junk
$loop:
$ read/end=end_loop/error=error input record
$ write/error=error temp record
$ goto loop
$end_loop:
$ close input
$ close temp
$ rename 'temp' trialcr.txt
$ goto exit
$error:
$ write sys$output "Unexpected error: " + f$message ($status)
$ goto exit
$exit:
$ exit

Upvotes: 2

Related Questions