Operating System - OpenVMS
1753482 Members
4247 Online
108794 Solutions
New Discussion юеВ

Re: same function with awk in unix

 
vpar
Advisor

same function with awk in unix

Hi

What is same function of openvms with awk of unix?

In example;

#ls -l | awk '{print $1}'

How to use above function in openvms?

Regards
4 REPLIES 4
Duncan Morris
Honored Contributor

Re: same function with awk in unix

Vpar,

welcome to the ITRC OpenVMS forum!

There is no direct equivalent of awk in OpenVMS, but depending upon your environment, you may be able to use other tools.

Try searching the OpenVMS forum for "awk".

useful results include:

http://h30499.www3.hp.com/t5/Languages-and-Scripting/KSH-to-DCL-command-question-easy/m-p/3742697#M2091


http://h30499.www3.hp.com/t5/Languages-and-Scripting/DCL-Search/m-p/3755839#M2204


http://h30499.www3.hp.com/t5/System-Management/awk-external-command-and-quotes/m-p/4008088#M17182


Here is a trivial sample command procedure showing how the DCL lexical function f$element could achieve a solution to your simple enquiry.

$ set nover
$ bash
ls -l >> fred.tmp
exit
$ open/read inp_fil fred.tmp
$ write sys$output "---- VMS style ----"
$loop1:
$ read/end=end_loop1 inp_fil inp_rec
$ write sys$output f$element(0," ",inp_rec)
$ goto loop1
$end_loop1:
$ close inp_fil
$ del/noconf/nolog fred.tmp.*
$!
$! or
$!
$unix_style:
$ write sys$output "---- Unix style ----"
$ bash
ls -l | awk '{print $1}'
exit
$ del/noconf/nolog fred.tmp.*
$exit

Of course, if you have GNV installed then you could simply write your own scripts using gawk.

Regards,

Duncan

Steven Schweda
Honored Contributor

Re: same function with awk in unix

> How to use above function in openvms?

The best answer is probably that one would
not normally do anything like that in VMS
(DCL). If you're looking for file
permissions (called "protections" here), then
there are other, better ways to get them.
For example:

ALP $ write sys$output f$file_attributes( "login.com", "PRO")
SYSTEM=RWED, OWNER=RWED, GROUP=RE, WORLD=RE

Note that this is done entirely in DCL,
without running a program like "ls" or "awk".
VMS is not a UNIX(-like) operating system,
so the best way to do something in VMS is
often not the UNIX way.

Is there some actual problem which you are
trying to solve? As usual, it can be more
helpful to ask how to get a particular result
than it is to ask how to implement some
particular (sub-optimal) "solution".
Hein van den Heuvel
Honored Contributor

Re: same function with awk in unix

I'm with Steve here.
What is the read problem you are trying to solve here?
A) get awk to go? install gawk and be happy
B) get LS -L to go? switch into a gnv/bash environment
C) get particular file attributes like owner or protection in a script?
C1: Use DCL F$FILE lexical
C2: Check out PERL. All the Unix fstat file functions like -M for modification timer, or -s for size are there.
D) trying to print a first field on a line?
D1) as per Duncan... DCL Lexical F$ELEMENT (often on F$EDIT TRIM+COMPRESS pre-process)
D2) use standard PERL techiques.

Overall i suspect the answer is : use Perl !
Cheers,
Hein
Hein van den Heuvel
Honored Contributor

Re: same function with awk in unix

Update?

Thanks,
Hein