?
Solved

bash sed insert text to a line that matches

Posted on 2011-09-19
1
Medium Priority
?
279 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
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…
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…
Suggested Courses

770 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