如何解析半JSON文件?
我有一个服务器日志,看起来像:如何解析半JSON文件?,json,parsing,logging,Json,Parsing,Logging,我有一个服务器日志,看起来像: <timestamp> <process>: Requesting information from the server with header: { userID: "myname" age: "20" } and body: { myotherinfo = { education = undergrad job = engineer hobbies = [piano, tenis]
<timestamp> <process>: Requesting information from the server with header: {
userID: "myname"
age: "20"
}
and body: {
myotherinfo = {
education = undergrad
job = engineer
hobbies = [piano, tenis]
}
}
:正在使用标头从服务器请求信息:{
用户名:“我的名字”
年龄:“20”
}
和机构:{
myotherinfo={
教育=本科
工作=工程师
爱好=[钢琴,泰尼斯]
}
}
此文件看起来只像JSON,但缺少“
,
”分隔符,并包含一组句子字符串。如何解析这个字符串,以便像访问真正的JSON文件一样访问它?例如,当我想键入“标题
”时,它应该返回标题的所有属性。我还应该能够键入“header.age
”等。听起来您基本上有两个选择:
1) 用你最喜欢的语言编写一个脚本来解析文件:Perl、Java、C#、Python——随便什么
。。。或者
2) 使用类似的方法创建您自己的解析器
以下是关于后者的一些教程:
sed-n'/header/,/}/p'myfile.txt
@paulsm4您能简要解释一下您的sed命令吗?