Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Unix command to update contents of a file

Posted on 2005-02-25
Medium Priority
Last Modified: 2010-04-21
Hi guys,
Need some help with writing a unix pipeline that updates the content of a file by replacing all the matches of wordX with the symbol '&' and replacing each word at the end of a line with wordY.  If the command completes sucessfully it should print 'YES' otherwise print 'NO'


Question by:gopalpatel
LVL 46

Accepted Solution

Kent Olsen earned 2000 total points
ID: 13405180

If you mean replacing wordX<newline> with wordY<newline>, the following should work:

sed -e 's/wordX$/WordY$/g' -e 's/wordX/&/g' < SourceFile > DestinationFile


Author Comment

ID: 13405243

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

572 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