Advertisement

08.05.2008 at 12:35PM PDT, ID: 23623543
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

How to parse an array with multiple space characters (define delimeter)?

Asked by jrram in Shell Scripting

Tags: ,

Good afternoon all,

I'm hoping someone could help me fix an issue I'm having with my code.  In the code below, I am trying to parse an file and run a series of SQL statements.  

To do this, I use a grep statement to get the list of all the "setup_sql" lines in the file.  I store these in an array.  Then, I try to use a for loop to read each line and run the statement against my database.  The problem is I think by default the "space" characters is used as the delimiter in the loop so the complete statement is being executed.

On the first pass, instead of "UPDATE AP_VENDOR SET PAYMENT_TERMS = 'CHK' WHERE STATUS = 'ACTIVE'" being executed, "UPDATE" is.

It executes like this.
query 1: UPDATE
query 2: AP_VENDOR
query 3: SET
...

How should I modify my code so that I can capture the entire line.  In the below scenario only two SQL statements should be executed.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
XML File:
 
                <indicator id="IND_01">
                        <secnum>1</secnum>
                        <turn_on>N</turn_on>
                        
                        <setup_db>OVERSIGHT</setup_db>
                        <setup_sql>UPDATE AP_VENDOR SET PAYMENT_TERMS = 'CHK' WHERE STATUS = 'ACTIVE'</setup_sql>
                        <setup_sql>UPDATE AP_VENDOR SET NAME1 = null WHERE VENDOR_ID = 'VENID-1'</setup_sql>
                        <setup_verify_sql>SELECT COUNT(*) FROM AP_VENDOR WHERE NAME1 is null</setup_verify_sql>
                        <setup_verify_count>1</setup_verify_count>
                        
                        <ordinal>0</ordinal>
                        <conf>0.2</conf>
                </indicator>
 
My Code:
#Get list of setup sql lines
ssql=`echo "IND_01" | grep "setup_sql" | sed "s/<[\/]*setup_sql>//g"`
 
for statement in $s_sql;
do
 'execute database statement
done
 
Keywords: How to parse an array with multiple sp…
 
Loading Advertisement...
 
[+][-]08.05.2008 at 01:49PM PDT, ID: 22165056

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Shell Scripting
Tags: Linux, Bash
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.06.2008 at 05:07AM PDT, ID: 22169178

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628