-   Linux - Newbie (
-   -   sed append word at end of line if word is missing (

franjo124 02-19-2010 02:24 AM

sed append word at end of line if word is missing
I have to modify formsweb.cfg file in Oracle IAS.

Problem description

In formsweb.cfg file are two lines with labels archive_jini= and archive= at the beginning of line. After equal sign (=) is row of filenames of java archives delimited by coma(,). When I insert a new jar file in java directory, I have to append the very same name of jar file to both lines if that name is not yet present.

I would appreciate some (a lot!!!) help.

example snippet from formsweb.cfg

# Forms applet parameter
# Forms applet archive setting for JInitiator
# Forms applet archive setting for other clients (Sun Java Plugin, Appletviewer, etc)
# Number of times client should retry if a network failure occurs. You should
# only change this after reading the documentation.

David the H. 02-19-2010 02:41 AM

I think this should do it, assuming the sample is representitive of the whole. It works for me in testing:

sed -i.backup '/^archive/ {/foo.jar/! s/.*/&,foo.jar/}' formsweb.cfg
The first section matches any line starting with "archive", then the bracketed part searches for any of those lines that don't have foo.jar, and appends what you want to those lines.

The -i option edits the file in place, with .backup creating a backup of the original.

franjo124 02-19-2010 03:18 AM

And I was brain shaking :banghead: in my head for two days!
THX :hattip:


mijohnst 03-08-2012 08:41 PM

This is exactly what I was looking for tonight... David the H., you're the man... :)

All times are GMT -5. The time now is 07:16 PM.