Skip to content
WJunction - Webmaster Forum

How to change a string in a text file on a Linux server

Status
Not open for further replies.
So, you want an easy to to replace text in files, even multiple files, on a linux machine, from the command line.
How? - You ask? Easy.

Let me show you.
Let’s say you want to replace all instances of “John†with “Pete†in a file, called resume.txt
In a bash shell, run the following:
Code:

PHP Code:
PHP:
 replace John Pete — resume.txt


Now, how about replacing all instance of “/home/†with “/home2/� in all files located in /etc/? (let’s say you have moved the home folder)
Code:

PHP Code:
PHP:
 replace /home/ /home2/ — /etc/*


Or, you want to update your DNS servers quickly, after moving your servers to a new domain. The old domain was mydomain.com & the new domain is ourdomain.com
Code:

PHP Code:
PHP:
 	 replace mydomain newdomain — /var/named/*.db
 
Status
Not open for further replies.

About the author

A
Active Member · Joined
Windows Servers
88
Messages
4
Reactions
8
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom