Inserting text in a specific file in a specific point
Hi,
My .bash_profile is:
----------------------
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
----------------------------
What i'd like to do is from the command prompt or a bash script, insert text after the line "PATH=$PATH:$HOME/bin".
I've searched the web and tried a few tricks, but one worked :(
Could you help me please ?
Wam Regards,
MARG
quoth the MARG:
Quoted 19 lines
Hi,
My .bash_profile is:
----------------------# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrcfi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
----------------------------
Quoted 6 lines
What i'd like to do is from the command prompt or a bash script, insert text after the line "PATH=$PATH:$HOME/bin".
I've searched the web and tried a few tricks, but one worked :(
Could you help me please
sed is the tool you need.
Try something like:
sed -e '10a\some text\' .bash_profile
Quoted 2 lines
Wam Regards,
MARG
-d
Signature · 3 lines
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972
Hi Darren,
Thank you for your answer.
I tried that already and it works.
Problem is, it is assuming that the PATH line is line 10 and in other systems it may not be.
Any ideas ?
Warm Regards,
MARG
PS: Thank you Scott for the cool link.
Quoted 42 lines · darren kirby
quoth the MARG:
Quoted 19 lines
Hi,
My .bash_profile is:
----------------------# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrcfi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
----------------------------Quoted 6 lines
What i'd like to do is from the command prompt or a bash script, insert text after the line "PATH=$PATH:$HOME/bin".
I've searched the web and tried a few tricks, but one worked :(
Could you help me please
sed is the tool you need.
Try something like:
sed -e '10a\some text\' .bash_profile
Quoted 2 lines
Wam Regards,
MARG-d
quoth the MARG:
Quoted 11 lines
Hi Darren,
Thank you for your answer.
I tried that already and it works.
Problem is, it is assuming that the PATH line is line 10 and in other systems it may not be.
Any ideas ?
Ok, so you will have to use sed to find the PATH line using a regex, then print your line right after...
sed -e '/PATH=\$PATH/a some text' .bash_profile
Quoted 3 lines
Warm Regards,
MARG
PS: Thank you Scott for the cool link.
-d
Quoted 43 lines
Quoted 29 lines · darren kirby
quoth the MARG:
Quoted 19 lines
Hi,
My .bash_profile is:
----------------------# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrcfi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
----------------------------Quoted 6 lines
What i'd like to do is from the command prompt or a bash script, insert text after the line "PATH=$PATH:$HOME/bin".
I've searched the web and tried a few tricks, but one worked :(
Could you help me please
sed is the tool you need.
Quoted 8 lines
Try something like:
sed -e '10a\some text\' .bash_profile
Quoted 2 lines
Wam Regards,
MARG-d
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972
Quoted 1 line · MARG
Hi,
<sweep>
Quoted 4 lines
What i'd like to do is from the command prompt or a bash script, insert text after the line "PATH=$PATH:$HOME/bin".
I've searched the web and tried a few tricks, but one worked :(
It is good that you have searched the we...
What have you tried, maybe that will help us to help you.
Here is some good reading for you, it will be very helpful for you to gain help of some more experienced admins:
http://www.catb.org/~esr/faqs/smart-questions.html
Enjoy.
--
Scott
Quoted 11 lines · MARG
My .bash_profile is:
----------------------# .bash_profile# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrcfi
# User specific environment and startup programs
Quoted 8 lines
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
----------------------------What i'd like to do is from the command prompt or a bash script, insert text after the line "PATH=$PATH:$HOME/bin".
sed -e '/^PATH=/a\some text'
Signature · 1 line
Glynn Clements <[email protected]>