- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- DCL code to concatenate pairs of lines in a text f...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:05 AM
08-14-2006 02:05 AM
DCL code to concatenate pairs of lines in a text file
Any suggestions ?
Niall Godwin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:22 AM
08-14-2006 02:22 AM
Re: DCL code to concatenate pairs of lines in a text file
$ open/read i ifile
$open/write o ofile
$loop:
$ i1=""
$ i2=""
$ read/end=end i i1
$ read/end=end i i2
$ write o "''i1'''i2'"
$ goto loop
$end:
$ if i1 .nes. "" then write o "''i1'''i2'"
$ close i
$ close o
Wim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:24 AM
08-14-2006 02:24 AM
Re: DCL code to concatenate pairs of lines in a text file
you may simply open the textfile for reading and a new version for writing and scan the whole file, e.g.
$ open/read in file.dat
$ open/write out file.dat
$ loop:
$ read in line1
$ read in line2
$ write out line1,line2
$ goto loop
Be sure to add some error and end-of-file procssing and code for the possibility of an uneven number of lines.
regards Kalle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:29 AM
08-14-2006 02:29 AM
Re: DCL code to concatenate pairs of lines in a text file
Basically I would think you want to:
- open a file for reading
- create a loop
- initialize a counter
- read a line of data
- assign it to a symbol
- increment the counter
- read another line
- assign it to a second symbol
- increment the counter
- if the counter is 2
- add the two strings together by assigning to a third symbol
- do what you want with the concatenated string/symbol (write it to a file, display it on the screen etc.
- if no more lines left to read in original file
- close the original file
- do what ever else to terminate the procedure
- send an email, produce an OPCOM message etc.
- else
- reset the counter
- go read some more lines
You can test to see that the second line starts with a | as a "sanity" check in your code.
Depending on how often you need to do this, it might be easier just to do it with a "learned" keyboard sequence in TPU.
Is that what you're asking for?
HTH a bit,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:34 AM
08-14-2006 02:34 AM
Re: DCL code to concatenate pairs of lines in a text file
What do you want to do if a second line does NOT start with "|"
1) ignore the first line
2) concatenate this lien with the first and wait
3) output the first line and consider the current line a new first?
Here is some sample code for the latter case:
$close/nolog old
$close/nolog new
$open/read old old.txt
$create new.txt
$open/append new new.txt
$partial = 0
$loop:
$read/end=done old record
$if 0.eq.f$loc("|",record)
$then
$ write/sym new part,record
$ partial = 0
$ part = ""
$else
$ if partial
$ then
$ write new part
$ partial = 0
$ else
$ partial = 1
$ endif
$ part = record
$endif
$goto loop
$
$done:
$if partial then write new part
$close old
$close new
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:43 AM
08-14-2006 02:43 AM
Re: DCL code to concatenate pairs of lines in a text file
If you can trust the input, or want to concatenate anything before a line starting with "|" then a PERL solution becomes really easy:
$ type new.txt ! sample output from prior
een| twee
drie| vier
vijf
zes| zeven
$type old.txt !input for prior and this
een
| twee
drie
| vier
vijf
zes
| zeven
$
$ perl -pe "chomp unless (/^\|/) " old.txt
een| twee
drie| vier
vijfzes| zeven
or into a file:
$ perl -pe "chomp unless (/^\|/) " old.txt > new.txt
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 02:49 AM
08-14-2006 02:49 AM
Re: DCL code to concatenate pairs of lines in a text file
My US $ 0.02.
What about the cases where the length of the first line varies? Do you want a constant length first part, or is it just a matter of concatentation, regardless of the length of the first line?
Also, do you want to retain the "|" that precedes the second line?
- Bob Gezelter, http://www.rlgsc.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 03:57 AM
08-14-2006 03:57 AM
Re: DCL code to concatenate pairs of lines in a text file
The code below works fine but only when the concatenated string does not exceed the command element limit of 255 chars.
*************************************
$ open/read infile data.psv
$ open/write outfile data.psv;0
$loop:
$ linecount = 0
$ read/end_of_file=done infile line1
$ linecount = linecount + 1
$ read/end_of_file=done infile line2
$ linecount = linecount + 1
$ if linecount .eq. 2
$ then
$ concat = "''line1'" + "''line2'"
$ write outfile concat
$ endif
$ goto loop
$done:
$ close infile
$ close outfile
$ exit
***************************************
Unfortunately the string exceeds 255.
Is there a way around this?
Niall
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 04:09 AM
08-14-2006 04:09 AM
Re: DCL code to concatenate pairs of lines in a text file
use
$ write/symbol outfile concat
See $ HELP WRITE/SYMBOL
Volker.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 10:37 AM
08-14-2006 10:37 AM
Re: DCL code to concatenate pairs of lines in a text file
Which version of VMS are you running ?
Here is a recent link on DCL symbol limits.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1040077
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2006 11:29 AM
08-14-2006 11:29 AM
Re: DCL code to concatenate pairs of lines in a text file
If this is a one off, then it can be done quickly and simply in EVE. Assuming the "|", enable wildcards, then do a wild find for "\<|" (ie: beginning of line followed by vertical bar). Now LEARN a key sequence FIND NEXT then DEL. Next REPEAT more times than lines in the file and hit your LEARNed key. EXIT.
If it really is just every second line, then a learn sequence DOWN DOWN DEL repeated will also work (after fixing the first pair and setting your cursor to the beginning of the buffer).
If this is to be repeated many times, you can write a TPU script to do it. Example attached. Rename the file to GLUE.TPU and execute with:
$ EDIT/TPU/NODISPLAY/COMMAND=GLUE.TPU yourfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 01:13 AM
08-15-2006 01:13 AM
Re: DCL code to concatenate pairs of lines in a text file
Here is the working solution(contatenates 5 lines).
$Concat_Extract: SUBROUTINE
$!
$! DESCRIPTION
$! Concatenates multiple lines of data into one line.
$! Lines of data are read, 3 at a time, and concatenated into one before
$! writing the concatenated line to a new file.
$!
$! INPUTS
$! P1 Extract Filename
$!
$! OUTPUTS
$! New version of Extract, with lines concatenated
$! Exit status set to standard VMS status code
$!
$ original_file = p1
$ concatenated_file = p1 + ";0"
$!
$ call Format_Date " at "
$ msg = pre + "I-CONCAT, Concatenating lines in the extract file: " -
+ P1 + DATE_TIME
$ say msg
$!
$ open/read concatin 'original_file'
$ open/write concatout 'concatenated_file'
$!
$! Start looping through the file, concatenating every 5 lines into one.
$CONCAT_LOOP:
$ linecount = 0
$ read/end_of_file=done concatin line1
$ linecount = linecount + 1
$ read/end_of_file=done concatin line2
$ linecount = linecount + 1
$ read/end_of_file=done concatin line3
$ linecount = linecount + 1
$ read/end_of_file=done concatin line4
$ linecount = linecount + 1
$ read/end_of_file=done concatin line5
$ linecount = linecount + 1
$ if linecount .eq. 5
$ then
$ concat = "''line1'" + "''line2'"
$ concat = concat + "''line3'" + "''line4'" + "''line5'"
$ write/symbol concatout concat
$ endif
$ goto CONCAT_LOOP
$!
$DONE:
$ close concatin
$ close concatout
$!
$! Delete the original file by purging down to one version
$ purge/log statext
$!
$ exit
$!
$ENDSUBROUTINE ! Concat_Extract
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2006 02:19 AM
08-15-2006 02:19 AM
Re: DCL code to concatenate pairs of lines in a text file
For grins, try this:
$perl -i -pe "chomp if ++$i%5" tmp.txt
I believe it does all you want in one line.
If you wanted a space between segments:
$perl -i -pe "s/\n/ / if ++$i%5" tmp.txt
The -i stands for 'in place' and roughly matches:
$ perl -pe "chomp if ++$i%5" tmp.txt;-1 > tmp.txt
Btw.. your question was about pairs of lines, the comments mention 3 lines, the code uses 5 lines.
And your question mentions a recognizable last chunk... that would be my preferred way to code this in case the original files gets a lines off track. Either use it for a new line trigger, or use it to verify you are still in the right spot:
$ perl -pe "if (++$i%5) {s/\n/ /} else {die ""\n5th record does not start with |"" unless /^\|/}" tmp.txt
Cheers,
Hein.