LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-19-2010, 02:24 AM   #1
franjo124
LQ Newbie
 
Registered: Mar 2008
Posts: 14

Rep: Reputation: 0
Unhappy 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
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

Last edited by franjo124; 02-19-2010 at 02:26 AM.
 
Old 02-19-2010, 02:41 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
1 members found this post helpful.
Old 02-19-2010, 03:18 AM   #3
franjo124
LQ Newbie
 
Registered: Mar 2008
Posts: 14

Original Poster
Rep: Reputation: 0
Talking

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

Regards
Franjo
 
Old 03-08-2012, 08:41 PM   #4
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

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


Reply

Tags
end, line, sed, word



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed append text to end of line if line contains specific text? How can this be done? helptonewbie Linux - Newbie 4 10-23-2013 01:48 PM
[SOLVED] SED - substitute a word only in a certain line carolflb Linux - Newbie 3 02-02-2010 09:30 AM
print second word in 1st line along with 5th word in all the lines after the first bangaram Programming 5 08-31-2009 03:42 AM
Problems Copying & Pasting In Word When Word Closes - Ubuntu davidx Linux - Software 3 10-22-2008 08:21 PM
sed to delete a line for a word and line above cmontr Programming 11 07-03-2008 08:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration