regex - sed beginner changing all occurrences in a folder
regex - sed beginner: changing all occurrences in a folder
There is no way to do it using only sed. You’ll need to use at least the find utility together:
find . -type f -exec sed -i.bak "s/foo/bar/g" {} \;
This command will create a .bak file for each changed file.
Notes:
- The
-iargument forsedcommand is a GNU extension, so, if you are running this command with the BSD’ssedyou will need to redirect the output to a new file then rename it. - The
findutility does not implement the-execargument in old UNIX boxes, so, you will need to use a| xargsinstead.