I need to edit files with a specific template in their names. These files are distributed in several hierarchical directories.
I use findand then sedusing xargsto achieve the same result:
find . -type f -name "file*" | sed -i.bak 's/word1/replace_word1/g'
My problem is that now I want to undo the changes from the backup files (* .bak). An example directory tree will look like the one shown below. I am looking for a linux command (maybe a chain) to achieve the same.
$ tree
.
|-- pdir1
| |-- dir1
| | |-- dir2
| | | |-- file2
| | | `-- file2.bak
| | |-- file1
| | `-- file1.bak
| `-- dir3
| |-- file3
| `-- file3.bak
`-- pdir2
|-- file1
`-- file1.bak
I can find all backup files using the following command find. But I can’t understand what to do next. It would be noticeable if you could help me solve this problem.
find . -type f -name "file*.bak"
Note
. , script. .