Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

bash sed insert text to a line that matches

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…

618 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