Solved

Search and replace of text in a file using a script

Posted on 2008-06-17
4
229 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now