在bash的列中格式化输出

时间:2018-10-17 05:08:11

标签: bash string-formatting

您能帮我格式化“列”中的以下输出吗,所以当我为WWN grep时,我可以得到一个名称。这是一个大文件,超过1000行。

如果我在同一行中获得一行别名的别名,那么它会很棒。

================================================ =============

别名:a_name_A

            10:00:00:05:33:00:00:00; 10:00:00:05:12:12:23:00; 
            10:00:00:10:86:00:00:00

别名:a_name123_A

            20:00:00:10:56:05:12:23; 20:00:00:10:44:04:48:78; 
            20:00:00:10:67:78:90:00

别名:a_name2323_A

            20:00:00:00:44:33:22:11

别名:a_rep02_A

            20:00:00:33:33:44:55:55

=======================================

以CSV格式查看输出

a_name_A,10:00:00:05:33:00:00:00,10:00:00:05:12:12:23:00,10:00:00:10:86:00:00 :00

a_name123_A,20:00:00:10:56:05:12:23,20:00:00:10:44:04:48:78,20:00:00:10:67:78:90 :00

a_name2323_A,20:00:00:00:44:33:22:11

a_rep02_A,20:00:00:33:33:44:55:55

1 个答案:

答案 0 :(得分:0)

您可以使用类似的内容:

gawk '/alias/ {
        if(alias=="")
           alias=$2
        else
           {
           print alias data
           data=""
           alias=$2
           }
        next
}
{
        gsub(";",",",$0)
        gsub(" ","",$0)
        data=data $0
}
END {
       print alias data
}' data.txt