Solved

bash sed insert text to a line that matches

Posted on 2011-09-19
1
241 Views
Last Modified: 2012-05-12
hi,

I need assistance inserting in a line that matches certain word astring, this is for the bash_profile file.

PATH=/usr/local/jruby/bin:$JAVA_HOME/bin:$PATH:$HOME/bin


I would like to insert another path at the end of the line using sed. I would appreciate your input.

Regards,

Michael
0
Comment
Question by:dpoper1
1 Comment
 
LVL 21

Accepted Solution

by:
Papertrip earned 250 total points
Comment Utility
In this example, the string to match is 'PATH' at the start of a line.

[root@broken ~]# cat path.txt
PATH=/usr/local/jruby/bin:$JAVA_HOME/bin:$PATH:$HOME/bin
NOTPATH=/usr/local/jruby/bin:$JAVA_HOME/bin:$PATH:$HOME/bin

[root@broken ~]# sed '/^PATH/ s#$#:/newpath#' path.txt
PATH=/usr/local/jruby/bin:$JAVA_HOME/bin:$PATH:$HOME/bin:/newpath
NOTPATH=/usr/local/jruby/bin:$JAVA_HOME/bin:$PATH:$HOME/bin

Open in new window


0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

10 Experts available now in Live!

Get 1:1 Help Now