在 OpenVMS 中编写脚本很困难

发布于 2024-12-10 06:08:35 字数 927 浏览 0 评论 0原文

我在 OpenVMS 中编写脚本时遇到了困难 我在名为 test.txt 的文件中有一定的输出。例如:

[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-

我在 Linux 中编写了一个脚本,它有助于获取设备列下的所有信息,在本例中为 se0,s10,dn0。 我们可以在 OPEN VMS 中做类似的事情

Linux 脚本如下: 脚本:

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

输出:

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

让我知道是否可以实现, 预先感谢您

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天煞孤星 2024-12-17 06:08:35

假设您需要以“-”开头的行下方第一列中的任何内容
您可以在命令文件中尝试以下操作,例如 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

使用以下命令运行此脚本:

$ @extract_if test.txt

输出应与指定的一样。

看来你对AWK很熟悉。您还可以安装适用于 OpenVMS 的 GAWK。

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.

双马尾 2024-12-17 06:08:35

晚了两年......

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

我想我永远不会理解那些 Unix 脚本小家伙,他们认为他们需要 4 或 5 个管道命令,然后是合适的工具,一步完成所有事情。

将“cat”输出通过管道传输到 awk 或 perl 中是最明显、最令人讨厌的无知迹象。
哦,好吧……继续!
海因.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文