HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a comma ( , ) in between of a line in DCL/VMS script

 
SOLVED
Go to solution
Sk Noorul Hassan
Regular Advisor

Adding a comma ( , ) in between of a line in DCL/VMS script

I have the following lines & I want to add a comma (,) after HP1 in fisrt line & after HP2 in second line :

ABED,HP1,XX,YY,XX,ZZ
ABRGELE,HP2,XX,YY,XX,ZZ

My file contains almost 1000 lines like this & I want to insert the comma(,) in the line after the second parameter. Can anybody guide me on this please.
11 REPLIES
Volker Halle
Honored Contributor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

Hi,

there are probably a hundred different ways to do this.

I would use TPU and a LEARN sequence

FIND ,
CTRL-K ! Start LEARN sequence
FIND ! find next ,
FIND ! find next ,
, ! insert ,
KP0 ! goto start of next line
CTRL-R ! End LERARN sequence
F20 ! define F20 as learned key

Then hit F20 for each line in the file.

You may do: GOLD 1000 F20 as well.

Or you can write some DCL script, a Perl Script, a program etc.

Volker.
Sk Noorul Hassan
Regular Advisor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

Volker, I want it through DCL script as part of automatic batch job. Please guide me on this.
Hein van den Heuvel
Honored Contributor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

I would use PERL:

$ perl -pe "s/,(.*?,)/,$1,/" old > new

s/x/y/ # substitute x with y
, #find a first comma
( #remember
.*? #anything, any number of times, non-greedy
) # stop remembering
replace by
,$1, # a comma, what was remembered, an an extra comma.

Hein.
Bojan Nemec
Honored Contributor
Solution

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

A sample DCL sript:

$ open/read a INPUT_FILE
$ open/write b OUTPUT_FILE
$l:
$ read a line /end=end
$ outline = f$element (0 , "," , line)
$ i = 1
$l1:
$ el = f$element (i , "," , line)
$ if el.eqs."," then goto e1
$ outline = outline + "," + el
$ if i.eq.1 then outline = outline + ","
$ i = i + 1
$ goto l1
$e1:
$ write b outline
$ goto l
$end:
$ close a
$ close b


Replace INPUT_FILE and OUTPUT_FILE with yours file specifications.


Bojan
Hein van den Heuvel
Honored Contributor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

If I would use DCL (which I wouldn't :-) then I woudl not use the field loop, but just look for a comma twice:


$ open/read a INPUT_FILE
$ open/write b OUTPUT_FILE
$l:
$ read a line /end=end
$ first = f$loc(",",line)
$ rest = f$extr(first,999,line)
$ second = first + f$loc(",",rest)
$ outline = f$extr(0,second,line) + "," + f$extr(second,999,line)
$ write b outline
$ goto l
$end:
$ close a
$ close b

I _might_ make that more robust by making sure the F$LOC functions find something less tan F$LEN. Or I might make sure the outline is one longer than the inline, but probably not.

Cheers,
Hein.
Sk Noorul Hassan
Regular Advisor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

Thanks friends for reply. I will test it with my file & get back to you.

Many thanks...
Terry Yeomans
Frequent Advisor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

The best way I've done this before is to do the following:
EDIT/TPU filename
1 - Press the DO button (or Shift and F6)
2 - Type REPLACE
3 - Type HP1
4 - Type HP1,
5 - Type A (for ALL)
You will find a comma appears after all HP1's.
Repeat steps 1 to 5 for HP2.
Done in seconds.
Regards Terry.
Jan van den Ende
Honored Contributor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

Sk,

my favorite for such problems is EDIT/EDT in command mode.

A file (say, HPCOMMA.EDT) with EDT commands:

s/HP1,/HP1,,/wh
s/HP2,/HP2,,/wh
exit

And now, whereever/whenever this needs to be done:

$ ....
$ EDITT/EDT infile /COMM=HPCOMMA.EDT
$...

After this, you have an extra version of infile, with the sesired substitution done.

Explanation:
s/ .../ xxx / wh
substitute ... by xxx over the whole file.
Should "/" be in the replcements, then use another character, eg "?" or "#" as separator.

EDITT/EDT notice the extra "T". Whenever a symbol EDIT does, or might, exist, then that extra last letter forces using the native command instead of any symbol substitution.

Limitations:

No line can exceed 255 chars.
No way (that I know of) to manipulate record separators.

hth

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
FOX MULDER_2
Frequent Advisor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

Hi,

Edit/edt should be fine.

$ edit/edt filename
*substi/HP2/HP2,/whole

This should take care of the whole.

Fox
Sk Noorul Hassan
Regular Advisor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

Thanks very much. I could finish my job.
Wim Van den Wyngaert
Honored Contributor

Re: Adding a comma ( , ) in between of a line in DCL/VMS script

I'm with Bojan's solution. Perl is fine but you can not expect a system manager of VMS to know Perl or awk. DCL yes. EDT too but the DCL solution is easier, IMO.

WIm

Wim