I have a text file with output like this:
file_0108.json
2023-02-22T01:15:05.531+0000 connected to: mongodb://[**REDACTED**]@localhost
2023-02-22T01:15:08.531+0000 [######..................] db.coll 64.7MB/255MB (25.4%)
2023-02-22T01:15:11.531+0000 [############............] db.coll 128MB/255MB (50.3%)
2023-02-22T01:15:14.531+0000 [##################......] db.coll 196MB/255MB (76.9%)
2023-02-22T01:15:17.286+0000 [########################] db.coll 255MB/255MB (100.0%)
2023-02-22T01:15:17.286+0000 380757 document(s) imported successfully. 0 document(s) failed to import.
The file numbers (start of the block go from 0000 - 1000. Not all of the files imported successfully. How can I find every block of text in the file that starts with the file name, and ends with:
xxxxx document(s) imported successfully. 0 document(s) failed to import
then delete them, leaving only the errors?
Each block could have a different number of lines between the file name and the end of the block.
There are blocks with errors, but the errors can be different, so I thought it'd be easier to just remove the ones without errors.
Sample error block:
file_0293.json
2023-02-22T01:52:15.303+0000 connected to: mongodb://[**REDACTED**]@localhost
2023-02-22T01:52:16.836+0000 Failed: error processing document #46401: invalid character ',' after object key
2023-02-22T01:52:16.836+0000 46000 document(s) imported successfully. 0 document(s) failed to import.
…failed to import
, that would also remove all blocks with errors. And it's not helpful if the last line contains "0 document(s) failed to import". So how would we know an error occured? Search for "Failed:" or "error" in those blocks?file_NNNN.json
or can some not start withfile_
or not end with.json
or any other change? Are the lines with the file name the only lines that have just one field and no whitespace? Can you have whitespace in filenames?0 document(s) failed to import.
? Shouldn't you haveN document(s) failed to import.
whereN>0
?