Solved

Linux Bash Script Find Replace Single Line

Posted on 2013-01-20
3
462 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-
3 Comments
 
LVL 76

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

IT, Stop Being Called Into Every Meeting

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

707 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

15 Experts available now in Live!

Get 1:1 Help Now