• 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
  • 相关阅读:
    嵌入级联分类器
    AdaBoost 和 Real Adaboost 总结
    二分图匹配--匈牙利算法
    更新说明
    使用Visual Studio 2015 Community 开发windows服务
    C#字符串的不变性
    Windows 7 IIS HTTP 错误 500.21 – Internal Server Error 解决方法
    asp.net的请求管道事件
    Http请求过程
    css简单学习属性2---背景图片
  • 原文地址:https://www.cnblogs.com/Eivll0m/p/6072749.html
Copyright © 2020-2023  润新知