Loading....
Linux Command sed
in Linux sed is used to find some words to replace with another in one file or files in folders(recursive)
Example 1
below is recursive example: find "wordA" replace with wordB all files with extention ".php" in current folder
find . -type f -name "*.php" -exec sed -i '' 's/wordA/wordB/g' {} +
Example 2
below code find "wordA" replace with wordB files has a specific extension
sed -i -- 's/wordA/wordB/g' *product* ## all files whose name contains product
sed -i -- 's/wordA/wordB/g' *.php ## php files ending in .php
Example 3 Using regular expression
Replace wordA with wordB only if there is a "DDD" after on the same line:
sed -i 's/wordA\(.*DDD\)/wordB\1/' file
Example 4 Multiple replacement with different word pairs
sed -i 's/wordA/wordB/g; s/wordC/wordD/g; s/Muslum/William/g' file
or
Replace any of wordA, wordB or wordC with worldW
sed -Ei 's/wordA|wordB|wordC/worldW/g' file