小编Wil*_*own的帖子

使用shell脚本将文本文件中的问题转换为JSON格式

我有一个包含内容的文本文件:

//input.txt
1) What is the first month of the year?
a) March
b) February
c) January
d) December
Answer: c) January

2) What is the last month of the year?
a) July
b) December
c) August
d) May
Answer: b) December
Run Code Online (Sandbox Code Playgroud)

我想编写一个 shell 脚本,循环遍历此文件 input.txt (其中包含更多具有相同格式的内容)并生成类似于以下 JSON 的输出

[
 {
  "question": "What is the first month of the year?",
  "a": "March",
  "b": "February",
  "c": "January",
  "d": "December",
  "answer": "January",
 },
 {
  "question": "What is the last month of the …
Run Code Online (Sandbox Code Playgroud)

bash json

3
推荐指数
2
解决办法
101
查看次数

标签 统计

bash ×1

json ×1