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. |
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 |
Quote:
|
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. |
Try this:
sed -e "5 s%$% \"/home/${user_name}/test\"%" -i test.txt |
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. |