LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2013, 08:01 AM   #1
Ra'Jiska
Member
 
Registered: Apr 2013
Posts: 47

Rep: Reputation: Disabled
Adding Path at end of line


Hey,

I've a problem, I would like to know how to add a path at the end of the line of one of my .sh files.
When I do sed -e '5 s/$/ "/home/root/test"/' -i test.txt, I've an error due to "/" of the path, is therea is a way to tell to Mr.Linux I want to add this at the end of my file ?

Thanks for your help.

Last edited by Ra'Jiska; 06-15-2013 at 08:11 AM.
 
Old 06-15-2013, 08:22 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,968

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
You can use any character as the sed delimiter. Choose one that does not conflict, perhaps '%'.
Code:
sed -e '5 s%$% "/home/root/test"%' -i test.txt
 
Old 06-15-2013, 08:32 AM   #3
Ra'Jiska
Member
 
Registered: Apr 2013
Posts: 47

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
You can use any character as the sed delimiter. Choose one that does not conflict, perhaps '%'.
Code:
sed -e '5 s%$% "/home/root/test"%' -i test.txt
Worked perfectly, thanks a lot for the fast answer.
 
Old 06-15-2013, 09:11 AM   #4
Ra'Jiska
Member
 
Registered: Apr 2013
Posts: 47

Original Poster
Rep: Reputation: Disabled
One more thing, one can I do if I want to insert a variable in the path ?
Because now, if I want to put: sed -e '5 s%$% "/home/$user_name/test"%' -i test.txt

Thanks.
 
Old 06-15-2013, 10:44 AM   #5
xrgm
LQ Newbie
 
Registered: Dec 2012
Location: Joure, Netherlands
Posts: 7

Rep: Reputation: Disabled
Try this:
sed -e "5 s%$% \"/home/${user_name}/test\"%" -i test.txt
 
Old 06-16-2013, 08:28 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
If you literally want to just append it as the last (new) line of the file
Code:
echo '/home/root/test' >>test.text
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] AWK Adding a Period at the end of a line metallica1973 Programming 11 11-26-2012 03:05 PM
[SOLVED] sed question - adding backslash to end of line bradvan Programming 7 08-01-2012 05:35 AM
[SOLVED] Adding text to end of a particular line in bash dagummit Linux - General 7 11-30-2010 11:22 AM
Adding a Comma to the end of every nth line in Vi (or sed). Euler2 Linux - Newbie 6 10-12-2009 10:38 AM
adding new line at end of file airikah Programming 3 11-08-2003 05:27 AM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration