我有一个文本文件,其中每一行都具有以下结构,但单个字段的值不同,因此它们不具有相同的长度。例如,作者字段包含不同的名称。
{"cid": "z13k.16", "text": "Lor..ips", "time": "9 months ago", "author": "Jim Boe"}
我现在想要删除除包含特定作者" John Doe"的行之外的所有行。
另外" John Doe"可以出现在文本的其他部分。我只想在名字出现在"作者"类别。
答案 0 :(得分:1)
如果所有数据都在单行中,请在linux中使用此命令:
sed -i '/"author": "John Doe"/!d' your_file
或者只是
grep '"author": "John Doe"' your_file > your_file_cleaned