LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Adding Path at end of line (https://www.linuxquestions.org/questions/linux-newbie-8/adding-path-at-end-of-line-4175466115/)

Ra'Jiska 06-15-2013 07:01 AM

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.

rknichols 06-15-2013 07:22 AM

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

Ra'Jiska 06-15-2013 07:32 AM

Quote:

Originally Posted by rknichols (Post 4972359)
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.

Ra'Jiska 06-15-2013 08:11 AM

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.

xrgm 06-15-2013 09:44 AM

Try this:
sed -e "5 s%$% \"/home/${user_name}/test\"%" -i test.txt

chrism01 06-16-2013 07:28 PM

If you literally want to just append it as the last (new) line of the file
Code:

echo '/home/root/test' >>test.text


All times are GMT -5. The time now is 03:26 AM.