Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search and replace of text in a file using a script

Posted on 2008-06-17
4
Medium Priority
?
244 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
The viewer will learn how to dynamically set the form action using jQuery.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

824 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