Solved

Linux Bash Script Find Replace Single Line

Posted on 2013-01-20
3
476 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 77

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

827 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