Search and replace of text in a file using a script

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.
ostraatenAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
pzurowskiConnect With a Mentor Commented:
or maybe this one:
sed -i 's/localhost:3000/new_host:999/g' /path/to/a/file

Open in new window

0
 
michofreihaCommented:
$vi file_name
:%s/localhost:300/new_localhost/g[RETURN]
the  click the button Esc 2 times then type :wq then [Return]
0
 
michofreihaCommented:
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
 
ostraatenAuthor Commented:
Exactly what I was looking for, thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.