Shell script to replace all instances of a string in a file on Linux & Windows.
-
On Linux via bash script
sed “s/$stringToReplace/$replaceWith/g” $File_Name > $File_Name
-
On Windows using Powershell
( get-content $File_Name ) | % { $_ -replace $stringToReplace, $replaceWith } | set-content $File_Name
-
On Windows using Batch
set str=teh cat in teh hat
echo.%str%
set str=%str:teh=the%
echo.%str%Script Output:
teh cat in teh hat
the cat in the hat -
On Windows or Linux using Perl
perl -pi.orig -e “s/
/ /g;” -
On Windows or Linux using Python
Source:
The Cloud is the future: The AWS Certified Solutions Architect – Associate Average salary is $149,446/year. Get Certified Now with the apps below:
Get 20% off Google Workspace (including Google Meet) Business Plan (Americas): L9H4RENHLPH76FV
