The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to Extract Harikrishna SUN Solaris 3 06-20-2008 04:43 AM
extract using sed/awk - need help? Please!! gzs553 Shell Programming and Scripting 5 10-08-2007 05:54 PM
How to extract the PID from 'ps -ef' nsinha Shell Programming and Scripting 7 11-20-2006 07:47 AM
tar. I can't extract volleyboy UNIX for Dummies Questions & Answers 1 02-17-2006 11:54 AM
extract from TAR big123456 UNIX for Advanced & Expert Users 8 07-28-2005 04:00 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-26-2009
ArterialTool ArterialTool is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 11
Ok, new problem, ive got the following text file:



Code:
    <JDBCDataSource JNDIName="jdbc/rDB"
        Name="" PoolName="Othername"   Targets="myserver"/>
    <JDBCConnectionPool CapacityIncrement="2"
        DriverName="net.sourceforge.jtds.jdbc.Driver"
        InitialCapacity="4" MaxCapacity="20" Name="Othername"
        PasswordEncrypted="" Properties="user="
        Targets="myserver" TestConnectionsOnRelease="false" URL=""/>
    <JDBCDataSource JNDIName="jdbc/FirstDataBankDB" Name="fdbDataSource"
        PoolName="Othernamel" Targets="myserver"/>

<JDBCConnectionPool CapacityIncrement="5"
        DriverName="oracle.jdbc.driver.OracleDriver" InitialCapacity="5"
        MaxCapacity="35" Name="Othername"
        PasswordEncrypted=""
        PreparedStatementCacheSize="25"
        Properties=;dll=ocijdbc8;protocol=thin"
        RefreshMinutes="10" Targets="myserver"
        TestConnectionsOnRelease="false" TestConnectionsOnReserve="true"
        TestTableName="dual" URL=""/>

    <JDBCDataSource JNDIName="" 
        Name="ThisName"
        PoolName="l" RowPrefetchEnabled="true"
        RowPrefetchSize="100" Targets="myserver"
        CapacityIncrement="2"
        DriverName="net.sourceforge.jtds.jdbc.Driver"
        InitialCapacity="4" MaxCapacity="20" Name=""
        PasswordEncrypted="" Properties="user"
        Targets="myserver" TestConnectionsOnRelease="false" URL=""/>

    <JDBCDataSource JNDIName="jdbc/rDB"
        Name="" PoolName="Othername"   Targets="myserver"/>
    <JDBCConnectionPool CapacityIncrement="2"
        DriverName="net.sourceforge.jtds.jdbc.Driver"
        InitialCapacity="4" MaxCapacity="20" Name="Othername"
        PasswordEncrypted="" Properties="user="
        Targets="myserver" TestConnectionsOnRelease="false" URL=""/>
    <JDBCDataSource JNDIName="jdbc/FirstDataBankDB" Name="fdbDataSource"
        PoolName="Othernamel" Targets="myserver"/>
</Domain>

I need a SED function that isolates everything form "<JDBCDataSource" to "/>" where the Name parameter is "Name=ThisName". Ive tried modifying the range function given above, but I don't know how to make SED ignore the newline characters within a regular expression. The order of the entries is not guaranteed to be as listed and there can be many <JDBCDataSource entries.

---------- Post updated at 01:54 PM ---------- Previous update was at 01:24 PM ----------

I just thought of something. If I can get all of the entries on their own single line I could just grep for the "ThisName" parameter. Can anyone come up with a SED function that places everything in between "<" and "/>" on its own single line?

---------- Post updated at 02:57 PM ---------- Previous update was at 01:54 PM ----------

Or extract everything between the first occurrence of "<JDBCDataSource" before "Name=ThisName" and the first occurrence of "/>" after "Name=ThisName".

Last edited by ArterialTool; 08-26-2009 at 02:38 PM..
  #2 (permalink)  
Old 08-27-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,334
Try this:


Code:
tr '\n' '_' < file | tr '>' '\n'|sed '/Name="ThisName"/d'| tr '\n' '>'| tr '_' '\n'


But more simply with awk:


Code:
awk '/ThisName/{next}1' ORS="\n\n" RS=  FS="\n" file

Regards
  #3 (permalink)  
Old 08-27-2009
ArterialTool ArterialTool is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 11
Franklin52,

Neither solution seems to work, the AWK solution actually returns nothing.
  #4 (permalink)  
Old 08-27-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,937
ArterialTool, you really should consider using an XSL aware tool such as xsltproc for this type of work.

For example here is how you can use xsltproc to solve your original question

Code:
$ var=`xsltproc -param which "'min-pool-size'" file.xsl file.xml`
$ echo $var
2
$

where file.xml is your input file and file.xsl is

Code:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <!-- pass in as -param which "'value'"  -->
   <xsl;param name=which" />

    <xsl:output method="text'/>

   <xsl:template match="/">
      <xsl:apply-templates/>
   </xsl:template>

   <!-- output nodes that match -->
   <xsl:template match="*" priority="1">
      <xsl:if test="name(.)=$which">
        <xsl:value-of select="."/>
      </xsl:if>
   </xsl:template>

   <!-- eat all other output -->
   <xsl:template match="*|text()" priority="0"/>

</xsl:stylesheet>

  #5 (permalink)  
Old 08-27-2009
ArterialTool ArterialTool is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 11
I think your actually getting the opposite of what I am trying to get. I came up with this solution that seems to work:


Code:
cat file | awk '{printf("%s", $0); if ( $0 ~ /.*\/>/ ) {printf("\n");}}' | grep ThisName | tr -d '\n'

  #6 (permalink)  
Old 08-27-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,334
Quote:
Originally Posted by ArterialTool View Post
I think your actually getting the opposite of what I am trying to get. I came up with this solution that seems to work:


Code:
cat file | awk '{printf("%s", $0); if ( $0 ~ /.*\/>/ ) {printf("\n");}}' | grep ThisName | tr -d '\n'
Sorry, I misread the question but this should get the part you have colored:


Code:
awk '/ThisName/' ORS="\n\n" RS=  FS="\n" file

Regards
Reply

Bookmarks

Tags
faq, xml parsing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0