-1

I am on Oracle Solaris 10 and trying to grep a word from xml file using combination of awk and cut command. I have below mentioned string in xml file.

<Resource driverClassName="oracle.jdbc.OracleDriver"  name="jdbc/LiferayPool" type="javax.sql.DataSource" username="PROD_LIFERAY" password="" url="jdbc:oracle:thin:@server02:1521:PROD0100 " maxActive="20" maxIdle="10" minIdle="3" maxWait="10000" initialSize="3" validationInterval="60000" testOnBorrow="true" validationQuery="select 1 from dual" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"/>

I want to build awk command to grep word from the position where currently PROD0100 is shown in above example. I appreciate if someone can help me to figure out.

  • You should really use an XML parser for parsing XMK, in the meantime, try changing double quotes to newlines to see if that helps... `tr '"' '\n' < YourXMLfile` – Mark Setchell Jun 19 '17 at 13:51
  • Your question isn't clear. Do you want to print every line containing PROD0100 or print the string that occurs in the location that just happens to contain PROD0100 in your example or something else? [edit] your question to clarify your requirements and show us the expected output given your sample input plus what you've tried so far. – Ed Morton Jun 19 '17 at 13:56

1 Answers1

0

As usual with this sort of problem, there are many ways to solve it on Unix.

Awk matches patterns to actions, so you will need something like

/PROD0100/ {
    # your actions here on the matching line
}

By default, awk splits each line into fields that are delimited by spaces.

So if you use something like

gawk '/PROD0100/{ for (i=1;i<=NF;i=i+1) { if (match($i, ".*PROD0100.*") != 0) { print "matching word "$i } } }' test

(where test is the file to read containing the string) then you should get

matching word url="jdbc:oracle:thin:@server02:1521:PROD0100

However, for the input that you give you might have some problems because there is a space before the closing double quote in the word that gets found

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
  • Thanks Paul, I have edited description. I do not want to grep specific PROD0100 word, but the word located at that position. – Alpesh Bhavsar Jun 20 '17 at 05:08