Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell AWK-匹配多个图案并打印结果_Shell_Awk - Fatal编程技术网

Shell AWK-匹配多个图案并打印结果

Shell AWK-匹配多个图案并打印结果,shell,awk,Shell,Awk,使用我有限的脚本知识。。我编写了一个expect脚本,用于在特定设备上运行一些命令。下面是输出,它从所有设备保存到一个文件中(我刚刚列出了两个设备作为示例) l 我希望从输出中获取一些值,并将它们显示在行中,以“,”分隔: 有很多方法可以做到这一点,这里有一个基于util的方法(假设输入没有意外): ……甚至: lssystem | grep -i physical | xargs | { IFS=' :' read a b c d e f g ; echo "$f,$b,$d" ; } 有很

使用我有限的脚本知识。。我编写了一个expect脚本,用于在特定设备上运行一些命令。下面是输出,它从所有设备保存到一个文件中(我刚刚列出了两个设备作为示例)

l

我希望从输出中获取一些值,并将它们显示在行中,以“,”分隔:


有很多方法可以做到这一点,这里有一个基于util的方法(假设输入没有意外):

……甚至:

lssystem | grep -i physical |
xargs | { IFS=' :' read a b c d e f g ; echo "$f,$b,$d" ; }

有很多方法可以做到这一点,这里有一个基于util的方法(假设输入没有意外):

……甚至:

lssystem | grep -i physical |
xargs | { IFS=' :' read a b c d e f g ; echo "$f,$b,$d" ; }

我认为请求是将组合输出转换为单个CSV文件,因为使用“expect”执行的命令不能直接执行。下面是一个用于重新格式化组合输出的小脚本

awk -v OFS="," '
$1 == "lssystem" {
    key = cap = free = ""
} 
$1 == "physical_capacity" { cap = $2 }
$1 == "physical_free_capacity" { free = $2 }
$1 ~ /config>$/ {
    split($1, a, ":" ) ;
    key = a[2] ;
    print key, cap, free
    key = cap = free = ""
}
' < input-file

我认为请求是将组合输出转换为单个CSV文件,因为使用“expect”执行的命令不能直接执行。下面是一个用于重新格式化组合输出的小脚本

awk -v OFS="," '
$1 == "lssystem" {
    key = cap = free = ""
} 
$1 == "physical_capacity" { cap = $2 }
$1 == "physical_free_capacity" { free = $2 }
$1 ~ /config>$/ {
    split($1, a, ":" ) ;
    key = a[2] ;
    print key, cap, free
    key = cap = free = ""
}
' < input-file
awk -v OFS="," '
$1 == "lssystem" {
    key = cap = free = ""
} 
$1 == "physical_capacity" { cap = $2 }
$1 == "physical_free_capacity" { free = $2 }
$1 ~ /config>$/ {
    split($1, a, ":" ) ;
    key = a[2] ;
    print key, cap, free
    key = cap = free = ""
}
' < input-file
=== BEGIN name-of-host
lssystem | grep -i physical
physical_capacity 82.85TB
physical_free_capacity 20.50TB
IBM_FlashSystem:SU73VAWFS15:config>
=== END