Solved

bash sed insert text to a line that matches

Posted on 2011-09-19
1
263 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
[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
1 Comment
 
LVL 21

Accepted Solution

by:
Papertrip earned 250 total points
ID: 36563440
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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