How to Search & Replace Multiple Files in UNIX

Step 1 Open a blank file in any text editor.

Step 2 Place the following script into the the text editor:

echo "Type your find string followed by [Enter]:"
read fstring
echo "Type your replace string followed by [Enter]:"
read rstring
for y in `ls *`;
do sed "s/$fstring/$rstring/g" $y > temp; mv temp $y;

Step 3Save the script with the name "" in the same directory as the files you want to manipulate.

Step 4Open a Terminal Window. The terminal window will be found in the operating system's main "Application" menu, under either "System Tools" or "Utilities." You will be presented with a command prompt where you will type the following commands.

Step 5Type the command "mv " to move into the directory with the script. For example, the command would be "mv Files/" if the script was held in the "Files" directory in your home directory.

Step 6Type the command "chmod +x" to make the file executable.

Step 7Type the command "./" to execute the script.

No comments:

Post a Comment

Please Provide your feedback here