json数据包含问题的每个选项的值。我有一个包含所选选项的Excel工作表,我想使用此excel行从每个问题中获取结果记录。
{
_id: "6132057b3cb4244eaf3d0fcb77cff433",
_rev: "1-9ff5fb01438bbe8a2d72fd045f81d1aa",
StudentName: "Amna Arbab Khan Arbab Khan-1600000056",
group: "GGHS_HARNAI_G7",
collection: "sheet",
qid: "moodle-7-assess-180-242eb85d853b2c745ff6d646af796cc3",
quizname: "S Q03 G7",
qSeq: - {
0: "question-1528-1578465942",
1: "question-1531-1635449700",
2: "question-1533-70112158",
3: "question-1534-1525688068",
4: "question-1549-2053426302",
5: "question-1537-673398374",
6: "question-1542-784199047",
7: "question-1545-1869411269",
8: "question-1546-494683918",
9: "question-1547-706680857",
10: "question-1493-335020172",
11: "question-1497-1960104850",
12: "question-1498-2081091670",
13: "question-1499-2114481827",
14: "question-1501-763117186",
15: "question-1502-715530806",
16: "question-1504-1889103686",
17: "question-1506-1549843058",
18: "question-1507-826548044",
19: "question-1508-1159104816",
20: "question-1479-1070423976",
21: "question-1480-1565758164",
22: "question-1481-455420506",
23: "question-1482-1724535821",
24: "question-1483-1787441959",
25: "question-1484-434395472",
26: "question-1485-567210255",
27: "question-1486-203231914",
28: "question-1487-2048962791",
29: "question-1488-142969271"
},
optSeq: - {
question-1528-1578465942: - {
A: "5240",
B: "5241",
C: "5242",
D: "5243"
},
question-1531-1635449700: - {
A: "5252",
B: "5253",
C: "5254",
D: "5255"
},
question-1533-70112158: - {
A: "5260",
B: "5261",
C: "5262",
D: "5263"
},
question-1534-1525688068: - {
A: "5264",
B: "5265",
C: "5266",
D: "5267"
},
question-1549-2053426302: - {
A: "5324",
B: "5325",
C: "5326",
D: "5327"
},
question-1537-673398374: - {
A: "5276",
B: "5277",
C: "5278",
D: "5279"
},
question-1542-784199047: - {
A: "5296",
B: "5297",
C: "5298",
D: "5299"
},
question-1545-1869411269: - {
A: "5308",
B: "5309",
C: "5310",
D: "5311"
},
question-1546-494683918: - {
A: "5312",
B: "5313",
C: "5314",
D: "5315"
},
question-1547-706680857: - {
A: "5316",
B: "5317",
C: "5318",
D: "5319"
},
question-1493-335020172: - {
A: "5100",
B: "5101",
C: "5102",
D: "5103"
},
question-1497-1960104850: - {
A: "5116",
B: "5117",
C: "5118",
D: "5119"
},
question-1498-2081091670: - {
A: "5120",
B: "5121",
C: "5122",
D: "5123"
},
question-1499-2114481827: - {
A: "5124",
B: "5125",
C: "5126",
D: "5127"
},
question-1501-763117186: - {
A: "5132",
B: "5133",
C: "5134",
D: "5135"
},
question-1502-715530806: - {
A: "5136",
B: "5137",
C: "5138",
D: "5139"
},
question-1504-1889103686: - {
A: "5144",
B: "5145",
C: "5146",
D: "5147"
},
question-1506-1549843058: - {
A: "5152",
B: "5153",
C: "5154",
D: "5155"
},
question-1507-826548044: - {
A: "5156",
B: "5157",
C: "5158",
D: "5159"
},
question-1508-1159104816: - {
A: "5160",
B: "5161",
C: "5162",
D: "5163"
},
question-1479-1070423976: - {
A: "5044",
B: "5045",
C: "5046",
D: "5047"
},
question-1480-1565758164: - {
A: "5048",
B: "5049",
C: "5050",
D: "5051"
},
question-1481-455420506: - {
A: "5052",
B: "5053",
C: "5054",
D: "5055"
},
question-1482-1724535821: - {
A: "5056",
B: "5057",
C: "5058",
D: "5059"
},
question-1483-1787441959: - {
A: "5060",
B: "5061",
C: "5062",
D: "5063"
},
question-1484-434395472: - {
A: "5064",
B: "5065",
C: "5066",
D: "5067"
},
question-1485-567210255: - {
A: "5068",
B: "5069",
C: "5070",
D: "5071"
},
question-1486-203231914: - {
A: "5072",
B: "5073",
C: "5074",
D: "5075"
},
question-1487-2048962791: - {
A: "5076",
B: "5077",
C: "5078",
D: "5079"
},
question-1488-142969271: - {
A: "5080",
B: "5081",
C: "5082",
D: "5083"
}
}
}
我在Excel工作表中为每个问题选择了选项,如何为每个问题选择选项。
这是我在excel中的行。
[A D A B B B A B B B A B C A D B D D A A A B C D A C D A B B]
答案 0 :(得分:0)
Unix解决方案。让f1
成为大文件,f2
为所选选项。
0)在开始之前...将f1翻译为json:
sed -r -e 's/(\S+)\s*:/"\1" :/' -e 's/-\s*\{/\{/' f1 > f1.json
1)应用名为json
的json工具来提取optSeq选项
$ cat f1.json | json optSeq | json -M -a value > optseq.json
# cat optseq.json
{ "A": "5240", "B": "5241", "C": "5242", "D": "5243" }
{ "A": "5252", "B": "5253", "C": "5254", "D": "5255"}
...
2)为了从之前的选项A B C
中选择我们可以:
$ cat optseq.json| json -g 0.A 1.B 2.C
5240
5253
...
3)从f2中选择选项:grep -oP '\w' f2 | nl -v0 -s.
$ cat optseq.json| json -g $(grep -oP '\w' f2 | nl -v0 -s.)
最后)答案:
$ sed -r -e 's/(\S+)\s*:/"\1" :/' -e 's/-\s*\{/\{/' f1 > f1.json
$ json optSeq < f1.json| json -Ma value | json -g $(grep -oP '\w' f2| nl -v0 -s.)
5240
5255
5260 ...