• awk将普通文本转换成json文件


    script1:

    #!/bin/bash
    #Date:2016-11-16
    #Author:eivll0m
    
    awk -F"	" -vq='"' '{
            a[$1]=a[$1]?a[$1]"	"$2"	"$3"	"$4:$2"	"$3"	"$4
            }END{
                    for(i in a){
                            printf i"	[";l=split(a[i],b,"	");
                  for(j=1;j<=l;j+=3){ printf "{h_name"":"q b[j] q",";
                       printf "level"":"q b[j+1] q",";
                       printf "addres"":"q b[j+2] q"}," } print "]" } }' yy.txt|sed 's/,]$/]/' >>yy_json.txt

    script2:

    #!/bin/bash
    #Date:2016-11-17
    #Author:eivll0m
    
    awk -F"	" -vq='"' '
            function json(x,y){printf("%s:%s,",q x q, q y q)}
            function json2(x,y){printf("%s:%s",q x q, q y q)}
            function json3(x,y){printf("%s:%s",q x q, y)}
                    {
                            printf "{";
                  json("id",$2); printf q"essential_info"q":{"; json("name",$1); json("introduction",$3); json("medical_insurance",$4); json("alias",$5);
                  json("position",$6); json("infectivity",$7); json("route_of_transmission",$8); json2("multiple_population",$9);
                  printf "},"; printf q"symptom"q":{"; json("typical",$10); json2("content",$11);
                  printf "},"; json("pathogeny",$12);
                  json("prevent",$13); printf q"inspect"q":{"; json("item",$14); json2("content",$15);
                  printf "},"; json("differentiate",$16); printf q"treat"q":{"; json("mode",$17); json2("content",$18);
                  printf "},"; json("nurse",$19); json("complication",$20); json3("hospital",$21); print "}" }' jibin.TXT >jibin.json
  • 相关阅读:
    js类型自动转换以及==对比规则
    js改变作用域链
    cookie简单实例
    js操作cookie
    body设置margin为0
    inline-block和block元素水平居中显示
    执行git clone遇到警告解决办法
    git中各大写字母表示含义
    git命令报错
    linux.txt
  • 原文地址:https://www.cnblogs.com/Eivll0m/p/6072749.html
Copyright © 2020-2023  润新知