Solved

bash sed insert text to a line that matches

Posted on 2011-09-19
1
252 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
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…

803 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