I've got a text file with data that I want to select lines matching
certain character strings, then extract string values from the selected
lines by character position. On Unix, I would use awk or Perl. Does VMS
have a similar tool, should I use my favorite programming language and
call the STR$ RTL, can I write a TPU script to do this, or should I
transfer the file to a Unix box and user awk or Perl? ;)
I've got a text file with data that I want to select lines matching
certain character strings, then extract string values from the selected
lines by character position. On Unix, I would use awk or Perl. Does VMS
have a similar tool, should I use my favorite programming language and
call the STR$ RTL, can I write a TPU script to do this, or should I
transfer the file to a Unix box and user awk or Perl? ;)
I've got a text file with data that I want to select lines matching
certain character strings, then extract string values from the selected
lines by character position. On Unix, I would use awk or Perl. Does VMS
have a similar tool, should I use my favorite programming language and
call the STR$ RTL, can I write a TPU script to do this, or should I
transfer the file to a Unix box and user awk or Perl? ;)
On 10/13/2024 11:04 AM, David Meyer wrote:
I've got a text file with data that I want to select lines matching
certain character strings, then extract string values from the selected
lines by character position. On Unix, I would use awk or Perl. Does VMS
have a similar tool, should I use my favorite programming language and
call the STR$ RTL, can I write a TPU script to do this, or should I
transfer the file to a Unix box and user awk or Perl? ;)
Both Perl and gawk are available for VMS.
VSI distribute Perl - Alpha and Itanium here https://vmssoftware.com/products/perl/ - x86-64 I believe comes with VMS
Gawk you can get from the net - https://vms.process.com/scripts/fileserv/fileserv.com?GAWK
You can also use some other script language: Python, Groovy etc..
(I like Groovy)
A traditional VMS language (Cobol,Fortran,Basic,Pascal) and builtin
string functionality or STR$ calls will likely be much more code.
Arne
I've got a text file with data that I want to select lines matching
certain character strings, then extract string values from the selected
lines by character position. On Unix, I would use awk or Perl. Does VMS
have a similar tool, should I use my favorite programming language and
call the STR$ RTL, can I write a TPU script to do this, or should I
transfer the file to a Unix box and user awk or Perl? ;)
On 10/13/2024 2:39 PM, Arne Vajhøj wrote:
On 10/13/2024 11:04 AM, David Meyer wrote:
I've got a text file with data that I want to select lines matching
certain character strings, then extract string values from the selected
lines by character position. On Unix, I would use awk or Perl. Does VMS
have a similar tool, should I use my favorite programming language and
call the STR$ RTL, can I write a TPU script to do this, or should I
transfer the file to a Unix box and user awk or Perl? ;)
Both Perl and gawk are available for VMS.
VSI distribute Perl - Alpha and Itanium here
https://vmssoftware.com/products/perl/ - x86-64 I believe comes with VMS
Gawk you can get from the net -
https://vms.process.com/scripts/fileserv/fileserv.com?GAWK
You can also use some other script language: Python, Groovy etc..
(I like Groovy)
A traditional VMS language (Cobol,Fortran,Basic,Pascal) and builtin
string functionality or STR$ calls will likely be much more code.
Using SEARCH and then a simple Basic program is not that much work.
For example:
SEARCH File1.txt "some text" /output=File2.txt
1Â Â Â On Error Goto 90
10Â Â Â Open "file2" For Input as File 1%
    Open "File2" For Output as File 2%
20Â Â Â Linput #1%, Z$
    Print #2%, Mid(Z$,?,?)
    Goto 20
90Â Â Â GoTo 99 If ERR=11
    On Error GoTo 0
99Â Â Â End
Simple
No having to know whatever is your favorite utility
I seriously doubt there would be much fewer characters
No, I didn't try it ...
But in a relevant script language then it should be a one statement
problem (although in most cases splitting that one statement over
multiple lines is a good thing for readability).
import java.nio.file.*
Files.lines(Paths.get("login.com"))
    .filter(line -> line.contains("java"))
    .map(line -> line[2..12])
    .forEach(System.out::println)
output pos 2..12 (pos is 0 based!) from all lines of login.com
that contains "java".
On 10/13/24 2:26 PM, Arne Vajhøj wrote:
But in a relevant script language then it should be a one statement
problem (although in most cases splitting that one statement over
multiple lines is a good thing for readability).
import java.nio.file.*
Files.lines(Paths.get("login.com"))
     .filter(line -> line.contains("java"))
     .map(line -> line[2..12])
     .forEach(System.out::println)
output pos 2..12 (pos is 0 based!) from all lines of login.com
that contains "java".
Opening an editor, typing all that in, running the java compiler, and
then running the compiled program all seems like a lot of work to me
when all you need to do is:
$ perl -nE "say substr($_, 2, 12) if $_ =~ m/java/i;" < login.com
It is not Java but Groovy, so compile is optional.
$ type s.groovy
import java.nio.file.*
Files.lines(Paths.get("login.com"))
    .filter(line -> line.contains("java"))
    .map(line -> line[2..12])
    .forEach(System.out::println)
$ type s.groovy
import java.nio.file.*
Files.lines(Paths.get("login.com"))
     .filter(line -> line.contains("java"))
     .map(line -> line[2..12])
     .forEach(System.out::println)
Note that it is probably more groovysk with:
$ type s2.groovy
import java.nio.file.*
Files.lines(Paths.get("login.com"))
    .filter({ it.contains("java") })
    .map({ it[2..12] })
    .forEach({ println(it) })
But I don't think that improves readability.
On 10/13/2024 2:57 PM, Dave Froble wrote:
Using SEARCH and then a simple Basic program is not that much work.
For example:
SEARCH File1.txt "some text" /output=File2.txt
1Â Â Â On Error Goto 90
10Â Â Â Open "file2" For Input as File 1%
     Open "File2" For Output as File 2%
20Â Â Â Linput #1%, Z$
     Print #2%, Mid(Z$,?,?)
     Goto 20
90Â Â Â GoTo 99 If ERR=11
     On Error GoTo 0
99Â Â Â End
Simple
No having to know whatever is your favorite utility
I seriously doubt there would be much fewer characters
No, I didn't try it ...
I have confidence in your VMS Basic skills.
On 10/13/2024 3:26 PM, Arne Vajhøj wrote:
On 10/13/2024 2:57 PM, Dave Froble wrote:
Using SEARCH and then a simple Basic program is not that much work.
For example:
SEARCH File1.txt "some text" /output=File2.txt
1 On Error Goto 90
10 Open "file2" For Input as File 1%
Open "File2" For Output as File 2%
20 Linput #1%, Z$
Print #2%, Mid(Z$,?,?)
Goto 20
90 GoTo 99 If ERR=11
On Error GoTo 0
99 End
Simple
No having to know whatever is your favorite utility
I seriously doubt there would be much fewer characters
No, I didn't try it ...
I have confidence in your VMS Basic skills.
But I am curious about how you iterate over the file.
Are there any benefits from this way compared to:
handler eof_handler
end handler
when error use eof_handler
while 1 = 1
get #1
! do whatever
next
end when
?
Arne
On 10/13/2024 3:26 PM, Arne Vajhøj wrote:
On 10/13/2024 2:57 PM, Dave Froble wrote:
Using SEARCH and then a simple Basic program is not that much work.
For example:
SEARCH File1.txt "some text" /output=File2.txt
1 On Error Goto 90
10 Open "file2" For Input as File 1%
Open "File2" For Output as File 2%
20 Linput #1%, Z$
Print #2%, Mid(Z$,?,?)
Goto 20
90 GoTo 99 If ERR=11
On Error GoTo 0
99 End
Simple
No having to know whatever is your favorite utility
I seriously doubt there would be much fewer characters
No, I didn't try it ...
I have confidence in your VMS Basic skills.
But I am curious about how you iterate over the file.
Are there any benefits from this way compared to:
handler eof_handler
end handler
when error use eof_handler
while 1 = 1
get #1
! do whatever
next
end when
On 2024-10-13, Arne Vajhøj <arne@vajhoej.dk> wrote:
On 10/13/2024 3:26 PM, Arne Vajhøj wrote:
On 10/13/2024 2:57 PM, Dave Froble wrote:
Using SEARCH and then a simple Basic program is not that much work.
For example:
SEARCH File1.txt "some text" /output=File2.txt
1Â Â Â On Error Goto 90
10Â Â Â Open "file2" For Input as File 1%
     Open "File2" For Output as File 2%
20Â Â Â Linput #1%, Z$
     Print #2%, Mid(Z$,?,?)
     Goto 20
90Â Â Â GoTo 99 If ERR=11
     On Error GoTo 0
99Â Â Â End
Simple
No having to know whatever is your favorite utility
I seriously doubt there would be much fewer characters
No, I didn't try it ...
I have confidence in your VMS Basic skills.
But I am curious about how you iterate over the file.
Are there any benefits from this way compared to:
handler eof_handler
end handler
when error use eof_handler
while 1 = 1
get #1
! do whatever
next
end when
That's how a Pascal programmer would write it. David however clearly
prefers Dartmouth Basic. :-)
BTW, I think your approach is a lot more readable than David's style. :-)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 432 |
Nodes: | 16 (2 / 14) |
Uptime: | 29:22:04 |
Calls: | 9,081 |
Calls today: | 4 |
Files: | 13,409 |
Messages: | 6,022,004 |