'Removing strings partialling spanning multiple lines from a text file
I'm somewhat new to shell scripts, but inherited a complex set of them to debug and maintain.
My current issue is this. I need to remove text (badly formed json) that partially spans multiple lines.
{ label:"03/08/2022_23:59:47", y: 2757},
{ label:"03/08/2022_23:59:57", y: 2154},
{ label:"
//20_", y: },
{ label:"03/09/2022_00:00:10", y: 6422},
{ label:"03/09/2022_00:00:20", y: 7960},
{ label:"03/09/2022_00:00:30", y: 9472},
.... and at the end:
{ label:"03/20/2022_23:59:57", y: 26238},
{ label:"
//20_", y: }]}
As the bad text in lines 3 and 4 are also present at the end of the json stream, I really need to remove:
- the comma from the end of line 2
- line 3
- line 4 up to but not including the comma
I've looked at sed (works line by line) and tr (character by character). If their was no bad data at the end of the json stream this would be easy of course.
Oddly, this works perfectly in notepad of all things, just highlight the text search/replace, done. But I need to do this on hundreds of files...every day
Any ideas?
TIA!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
