Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

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

Feb 9, 2012, 10:01
Post: #1
How to change a string in a text file on a Linux server
How to change a string in a text file on a Linux server

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 Code:
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 Code:
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 Code:
replace mydomain newdomain — /var/named/*.db 

█| AvaNetco.com Hosting Company Shared Hosting , VPS , Dedicated
█| 24/7 Server Management, Outsourced Support, Web Development
█| High Quality virtual servers with lots of Guaranteed RAM and HDD space, Impeccable Service.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Information WINDOWS VPS v/s LINUX VPS vedas 1 103 May 5, 2012 09:46
Last Post: WHUK
  Dedicated Server Hosting & Shared Web Hosting Tyler Marcelo 5 155 Mar 30, 2012 12:41
Last Post: Asher ross
  Vps9.Net Netherlands Linux VPS Hosting 1Gbps @ 13€/mo. and 100Mbps @ 9€/mo VPS9.net 2 186 Mar 29, 2012 09:34
Last Post: b2netsolutions
  Vps9.Net Russia Linux VPS Hosting 100Mbps @ 9€/ VPS9.net 0 102 Mar 25, 2012 14:45
Last Post: VPS9.net
  WooServers: Linux Dedicated Servers for $20 - Check out Now! ronniekwar 3 382 Mar 24, 2012 03:36
Last Post: ranjani

Forum Jump:


User(s) browsing this thread:
1 Guest(s)

Return to Top