Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Extract string

Original Message
Name: William Polanco
Date: August 12, 2004 at 10:37:38 Pacific
Subject: Extract string
OS: OpenVMS AXP Version V7.3-
CPU/Ram: 256
Comment:
Dears, I am new in OPENVMS, I like to obtain a specific field from a string line, similar like awk.

Furthermore, what command in OPENVMS is similar a head o tail in unix.

Thanks for your help.


Report Offensive Message For Removal


Response Number 1
Name: WillemGrooters
Date: August 13, 2004 at 05:45:48 Pacific
Subject: Extract string
Reply: (edit)
Welcome to VMS world.

Your first line of knowlegde is HELP on the commandline ;-).

Other sources for help are www.openvms.org and the OpenVMS forum on www.hp.com (search for 'ITRC'. You need to register there but it's free)

To extract a specific field from a line:
It depends. If the fields are separated by a specific character, use F$ELEMENT:

Example (Type each line, without starting "$", at the prompt. ($ is the standard VMS prompt, usually used in typing when specifying code)

$var="1#one#st#first"
$nr=f$element(0,"#",var)
$nam=f$element(1,"#",var)
$ord=f$element(2,"#",var)
$onm=f$element(3,"#",var)
$! (! = comment character)
$sho sym nr
$sho sym nam
$sho sym ord
$sho sym onm

If you have no such delimiter, the command to extract part of a string is F$EXTRACT. You specify a starting position (actually: offset in the string, where the first character is at offset 0) and the size.
If you know what value you're looking for and it's size, but don't know the offset, use F$LOCATE to find the offset.

Example:

$ months="JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
$ dt = F$TIME() ! unix 'date' but in a different format
$ mmm=f$extract(3,3,dt)
$ m3= f$locate(mmm, months)
$ mm = m3/3 +1
$ sho sym mm

(Beware: although VMS is in essence case-insensitive, DCL is NOT! F$SEARCH will not find mm in months if case is different!)

If you specify:
$ months="JAN/FEB/MAR/APR/MAY/JUN/JUL/AUG/SEP/OCT/NOV/DEC"

you can do:

$ i=0
$LOOP:
$ IF F$ELEMENT(I, months) .EQS. mm THEN GOTO ENDLOOP
$ IF I .LE. 11 THEN
$ I = I+1
$ GOTO LOOP
$ ELSE
$ WRITE SYS$OUTPUT "Invalid month"
$ GOTO ENDLOOP
$ ENDIF
$ ENDLOOP
$

Just try them out.
'Scripting' in unix can be done in VMS as well, of course. Just invoke the editor, put above commands in a file and save it as a_job.COM. Start it by specifying:

$ @a_job

and it will execute each command.

But again: use HELP (and check the HP.COm site for OpenVMS documentation)

I don't know the unix 'head' command, but 'tail''s equivalent in VMS is:

$ TYPE/TAIL <filename>

Willem


Willem Grooters


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Extract string

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




CPU and Graphics Upgrade Questions

VIRUS ALERT in Taskbar, HELP!

DSHUB24 Connection Problems

need help with dsl and dial up

novel 3.12


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC