I'm trying to remove all dialogues from a txt book, how would i achieve that? I saw posts about using sed or awk, but what would be the exact format? Thank you
Copyright James Daniel Marrs Ritchey. This material was created for submission at 'how to remove content within double quotes from terminal in a plain text file', but can also be alternatively obtained from 'https://snippetly.blogspot.com/2019/12/delete-double-quoted-content.html' under the terms of any of the following licenses: Comprehensible Open License 3.0 (https://jamesdanielmarrsritchey.blogspot.com/2019/06/comprehensible-open-license-30.html), MIT (https://opensource.org/licenses/MIT).
To delete content between and including double quotes you could use preg_replace in PHP. Just make sure to make it non-greedy so it doesn't delete everything between the first and very last double quote.
<?php $text = <<<'EOT' This is some example text. Bob, "Yah, but it's not very interesting to read." Yet there is more example text of a similar nature. Natalie, "Please don't type anymore example text for me to read. It's really bad." Still, more example text is typed, because it is important that there be more text after the last dialogue example to ensure proper function of the code. David, "I think that's plently of example text!" David was correct. EOT; $new_text = preg_replace('/\"[\s\S]+?\"/', '', $text); echo $new_text; ?>
For Text File:
<?php $text = file_get_contents($file); $new_text = preg_replace('/\"[\s\S]+?\"/', '', $text); file_put_contents($new_file, $new_text); ?>