TurnKey Linux Virtual Appliance Library

Trivial question about sed command for a TKLPatch

Students are working on TKLPatch bundle for Ampache. We're stuck on what we think should be accomplished with sed: We want to insert a line in usage.txt with "Samba:     \\$ipaddr\media."

I'm using two reference books and not finding a solution that works.

I'm pretty sure we start sed -i - I then need a regular expression to direct it to a line number maybe?

sed -i '3 /Samba:....' \a usage.txt 

Is the closest I can get, and it seems far off. How do I direct it to a blank line? Do I need to escape blank spaces backslashes?

Our original draft had us placing a revised usage.txt in the overlay folder, but I figured a bash manipulation would be the preferred method.


Any feedback would be appreciated...

Alon Swartz's picture

Actually, the preferred method is using the overlay

As discussed in the usage tips and tricks, the recommended way to update the configuration console usage text is to use the overlay, as it's simpler than tweaking the file using something like sed, and less error prone.

Thanks for prompt reply.

In that case, it seems we have an Ampache patch ready to be bundled. Students will post a link today.

Landis Arnold's picture

Looking for the Tips and Tricks Link (and WIKI)

I think when things moved from ..  BZR?  to Git...

anyway, cant find Alon's link.  Working though similar subjects.

(Will Redirect to Git, but can't find anything related to tips or tricks)


thank you for any help

(redirect lands at:)


Landis A.

Landis Arnold's picture

Specifically I need to do 2 (1/2) things in a TKLDEV build

1:  I want to change the "openerp" database password for postgresql

2:  I want to insert that password also into the /opt/openerp/odoo/openerp-server.conf  (db_password = password ) that I have created and is using the default password  (basically 1 and 2 need to work together)

2 1/2:  I also need to change the admin_passwd = "PASS" line in the same file.  It is not seemingly set in the database.  



I have been struggling with the code in 


But no matter I am not getting any changes written to my openerp-server.conf file.  I do seem to call an inithook (causing some trouble on screen but system still installs to default). 

Perhaps should ask on tracker but seems a general question.  



Separate question re TKLDev and PIP also will be asked.

Landis A.

Jeremy's picture

If you are working with a PostgreSQL DB

Then the Mahara appliance is probably worth a look. It uses PostgreSQL DB backend so the inithooks should help out...

As for editing files using sed it is actually pretty easy. Ironically I used to think it was a dark art, but I use it a fair bit now and have the basics downpat. So say you wanted to find "text to find and delete" and wanted to replace it with "new text that replaces it" then you do it like this: "-i' for in place (i.e. edit a file in place) then enclose it in quotes; "s" to substitute; a delimiter (often a slash (/) is used but it can be hard to read sometimes so a pipe (|) is preferable. Then you end up with this:

sed -i "s|text to find and delete|new text that replaces it|" /path/to/file
Often I like to test to make sure it will work how I expect. Do that by echoing the text you want to edit and pipe it to sed (without the -i and the filename). I.e. like this:
echo "some text to find and delete and is awesome" | sed "s|text to find and delete|new text that replaces it|"

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)