Solved

Linux Bash Script Find Replace Single Line

Posted on 2013-01-20
3
479 Views
Last Modified: 2013-01-20
In my bash script I am trying to find and replace a single line in a file:

/etc/ntp.conf

server 0.ubuntu.pool.ntp.org

to

server time.nist.gov

Any quick way to do this? Sed?
0
Comment
Question by:-TNT-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 78

Expert Comment

by:arnold
ID: 38799795
perl -i.bak -pe 's/server 0.ubuntu.pool.ntp.org/server time.nist.gov/;' /etc/ntp.conf
An ntp.conf.bak will be created if a match/replacement occurs.

http://techome.wordpress.com/2007/12/22/perl-commandline-search-and-replace/
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 38799801
sed -i 's/server 0.ubuntu.pool.ntp.org/server time.nist.gov/' /etc/ntp.conf

Open in new window

0
 

Author Closing Comment

by:-TNT-
ID: 38800023
Perfect!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

752 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