Assume I have many *.txt
files on directory texts
with the below contents.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam tincidunt mauris eu risus.
Vestibulum auctor dapibus neque.
And I want to replace them with the following contents recursively.
Vestibulum commodo felis quis tortor.
Ut aliquam sollicitudin leo.
Cras iaculis ultricies nulla.
Donec quis dui at dolor tempor interdum.
As this is a quite large replacement. Typing each one of them can be time consuming.
Hence, I think it would be better if there is an option like this.
Copy and Paste the original texts into file original.txt
and the required replacements into another file update.txt
.
And then execute a command to find all the *.txt
files in the directory texts
that consist of the content in original.txt
and replace them with the contents of update.txt
.
Similar to simple replacements like:
find texts -name "*.txt" -exec sed -i 's/original/update/g' {} \;
I think this way there will be no mistakes as manual typing and less time will be consumed.
But I don't know what command I should use to achieve this? Is this possible.
However, first of all I must be able to verify the availability and number of occurrence of the original text.
Similar to Simple Checks like:
cd texts
grep -r --color=always "original" | wc -l
Thanks.