Solved

Linux Bash Script Find Replace Single Line

Posted on 2013-01-20
3
488 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 79

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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…
Fine Tune your automatic Updates for Ubuntu / Debian
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.
Suggested Courses

636 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