Shell script to Search and Replace words in .txt .xml or other text formats

Hi there.
Today i wrote this simple Shell script that can be useful for some of you.
Basically it replaces words inside a text file without the need to open the file. My case was i had to change paths to textures in a vrayscene file which had +35000 characters in it. It took a few seconds to do it with this.

—script—

#!/bin/bash
echo "drag file here"
read FICHEIRO
echo "search word"
read SEARCH
echo "replace word"
read REPLACE
echo "enter new file name"
read NEWFILE
sed s/"$SEARCH"/"$REPLACE"/g $FICHEIRO>"$HOME/Desktop/$NEWFILE"
 -----

save it as yourscriptname.sh and run it in terminal (Linux),
or as yourscriptname.command to run it on mac. It gets saved
on the desktop by default.
Advertisements

3 thoughts on “Shell script to Search and Replace words in .txt .xml or other text formats

  1. I found this post looking for a way to use Automator to create a Service that takes selected text and converts dashes to spaces, and then creates word caps for all the selected text. How would I go about this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s