0

I have searched and I don't know what I'm doing wrong but I can't find an answer to this question.

I have a file with all text stored as a single line. I am needing to find a pattern and remove all the text before and after that text until delimiters.

Ex. File

{"something":false,"more":"123","moresamerecord":"otherstuff"},{"something":false,"more":"abc","moresamerecord":"otherstuff"},{"something2":false,"more":"def","moresamerecord":"otherstuff"},{"something2":false,"more":"456","moresamerecord":"otherstuff"},

Keep in mind this is a single line with multiple records. I'm trying to find "abc" and remove everything between the previous and next record.

Expected outcome should be this.

{"something":false,"more":"123","moresamerecord":"otherstuff"},{"something2":false,"more":"def","moresamerecord":"otherstuff"},{"something2":false,"more":"456","moresamerecord":"otherstuff"},

I have been trying and unable to figure this out, any help would be appreciated.

ChSpan
  • 3
  • 1

1 Answers1

0

In principle something like

  1. format into lines, by sed
  2. delete whole lines, by using grep
  3. format back into stream, by perl

cat xyz | sed 's/},{/\n/' | grep -v 'abc' | perl -ape's/\n/},{/'

with brackets {} still need to be escaped ?

Peter
  • 1