LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed append word at end of line if word is missing (https://www.linuxquestions.org/questions/linux-newbie-8/sed-append-word-at-end-of-line-if-word-is-missing-790132/)

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.
:banghead:



example snippet from formsweb.cfg

# Forms applet parameter
serverApp=default
# Forms applet archive setting for JInitiator
archive_jini=frmall_jinit.jar,images.jar,paketi.jar,imgbean.jar
# Forms applet archive setting for other clients (Sun Java Plugin, Appletviewer, etc)
archive=frmall.jar,images.jar,in2kartica.jar,classes12.jar,HTTPClient.zip,imgbean.jar
# Number of times client should retry if a network failure occurs. You should
# only change this after reading the documentation.
networkRetries=30

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:
Code:

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:

Regards
Franjo

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:28 PM.