Skip to content
Advertisement

Remove string in file on linux

I am looking to remove the _id field and its value which changes:

{ "_id" : { "$oid" : "54da1bee58743hd23947f493" }, "name":"david", "age":"33"}
{ "_id" : { "$oid" : "5422222222222345d9f1f493" }, "name":"Dove", "age":"33"}
{ "_id" : { "$oid" : "54da1be57a4b727669f1f493" }, "name":"man", "age":"23"}


outcome:
{"name":"david","age":"33"}
{"name":"Dove", "age":"33"}
{"name":"man", "age":"23"}

I would like to use sed or any other command.

Advertisement

Answer

It is easy with jq.

jq -c 'del(._id)' input.txt

O/P:

{"name":"david","age":"33"}
{"name":"Dove","age":"33"}
{"name":"man","age":"23"}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement