Solved

Search and replace of text in a file using a script

Posted on 2008-06-17
4
233 Views
Last Modified: 2013-12-16
I have a script and in this srcipt I need to replace in another text file a servername 'localhost:3000' with another servername.

What is the simplest way to do this with Linux?

I know the path of the file in my script and  there is only one file I need to change, so I am looking for a simple command. That should suffice.
0
Comment
Question by:ostraaten
  • 2
4 Comments
 
LVL 9

Expert Comment

by:michofreiha
ID: 21807554
$vi file_name
:%s/localhost:300/new_localhost/g[RETURN]
the  click the button Esc 2 times then type :wq then [Return]
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 21807589
This will replace localhost:3000 in the initial file...to fo that in a new file make:
#cp file1 file2
#vi file2
#:%s......
Enjoy
0
 
LVL 3

Accepted Solution

by:
pzurowski earned 500 total points
ID: 21807594
or maybe this one:
sed -i 's/localhost:3000/new_host:999/g' /path/to/a/file

Open in new window

0
 

Author Closing Comment

by:ostraaten
ID: 31468145
Exactly what I was looking for, thanks!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question