Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linux Bash Script Find Replace Single Line

Posted on 2013-01-20
3
Medium Priority
?
492 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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

670 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