Fletchy
Fletchy

Reputation: 351

Delete line from file if matches regular expression

I am attempting to delete a line from a text file if it matches a regular expression. To accomplish this I was using sed in an Ubuntu environment combined with regular expressions. I have tried/referenced the following solutions: Sol1, Sol2, Sol3.

My current command is: sed '/[^"]+},/d' test.json with this command I am attempting to match and remove lines like:

{"hello},
{"go penguins!},
{"someone help1),

I am NOT trying to match or remove lines like: "should not match regex"}, Any line that ends with "}, should not be deleted.

I am not tied to using sed so any acceptable answer would work so long as my text file would look something like:

...
{"omg this is amazing"},
{"thanks for your help"},
{"no problem"},
...

Upvotes: 0

Views: 1588

Answers (2)

François B.
François B.

Reputation: 1174

It should by sed '/\"},/d' test.json (without !)

Upvotes: 0

Beta
Beta

Reputation: 99172

How about sed '/\"},/!d' test.json?

Upvotes: 1

Related Questions