Ziax Renas
Ziax Renas

Reputation: 1

Hard time with scripting in OpenVMS

I am having a very hard time with scripting in OpenVMS I have a certain output in a file called test.txt .For example :

[WWEWE@http-lx-as code]$ cat test.txt
** Configuration for file "MULTINET:NETWORK_DEVICES.CONFIGURATION" **

Device                           Adapter   CSR Address  Flags/Vector

------                           -------   -----------  ------------

se0  (Shared VAX/VMS Ethernet)   -NONE-    -NONE-       -NONE-

s10  (Serial Line IP)            -NONE-    -NONE-       -NONE-

dn0  (IP over DECNet link)       -NONE-    -NONE-       -NONE-

I have written a script in Linux which helps to pick up all the information under the device column in this case se0,s10,dn0. Can we do a similar thing in OPEN VMS

The Linux script is as follows : SCRIPT :

for i in `cat test.txt 2>/dev/null |egrep '^[a-z]' |grep -v '\*\*' | awk '{print $1}'`
> do
>     echo Begin-interface: $i
> done

OUTPUT :

Begin-interface: se0
Begin-interface: s10
Begin-interface: dn0

Let me know if it can be achieved, Thanking you in advance

Upvotes: 0

Views: 3004

Answers (2)

Hein
Hein

Reputation: 1463

Two years late....

$ gawk/comm="/^[a-z]/{print ""Begin-interface:"",$1}" test.tmp
Begin-interface: se0
Begin-interface: s10
Begin-interface: dn0

Guess I will never understand those Unix script weenies which think they need 4 or 5 piped commands, then the proper tool and do everything in one step.

Piping 'cat' output into awk or perl is the most obvious and obnoxious sign of clueless-ness. Oh well... Onwards! Hein.

Upvotes: 1

Peter Hofman
Peter Hofman

Reputation: 658

Assuming that you need anything in the first column below the line starting with '-' you can try the following in a command file, e.g. extract_if.com

$    IF P1 .EQS. "" THEN GOTO nothing_specified
$    IF F$SEARCH( P1 ) .EQS. "" THEN GOTO file_not_found
$    parse_line = 0
$    OPEN/READ/ERROR=file_open_error infile 'P1'
$read_loop:
$    READ/ERROR=file_read_error/END_OF_FILE=end_of_file infile inline
$    IF F$LENGTH( F$EDIT( inline, "TRIM" ) ) .EQ. 0 THEN GOTO read_loop
$    IF parse_line .EQ. 1
$    THEN
$        interface = F$ELEMENT( 0, " ", F$EDIT( inline, "TRIM,COMPRESS" ) )
$        WRITE SYS$OUTPUT F$FAO( "Begin-interface: !AS", interface )
$    ELSE
$        parse_line = ( F$EXTRACT( 0,1,inline ) .EQS. "-" )
$    ENDIF
$    GOTO read_loop
$nothing_specified:
$    WRITE SYS$OUTPUT "No file specified"
$    GOTO finished
$file_not_found:
$    WRITE SYS$OUTPUT F$FAO( "File !AS not found", P1 )
$    GOTO finished
$file_open_error:
$    WRITE SYS$OUTPUT F$FAO( "Error opening file !AS", P1 )
$    GOTO finished
$file_read_error:
$    WRITE SYS$OUTPUT F$FAO( "Error reading from file !AS", P1 )
$    GOTO close_file
$end_of_file:
$close_file:
$    IF F$TRNLNM("infile").NES."" THEN CLOSE infile
$finished:
$    EXIT

Run this script using:

$ @extract_if test.txt

The output should be as specified.

It seems you are familiar with AWK. You can also install GAWK for OpenVMS.

Upvotes: 2

Related Questions