Solved

Search and replace of text in a file using a script

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

770 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