title: awk : trying to generate a query using awk
body: <p>I'm trying to write an awk program to generate a sql query, using the output from a pipe command. The output of the command will be something like this</p>
  
  <pre><code>Service name: APP1  
  Service name: APP2  
  Service name: APP3  
  Service name: APP4  
  Service name: APP5  
  Service name: APP6  
  Service name: APP7  
  Service name: APP8  
  Service name: APP9  
  </code></pre>
  
  <p>and the result I need is something like :</p>
  
  <pre><code>select 'APP1' x from dual union all  
  select 'APP2' from dual union all  
  select 'APP3' from dual union all  
  select 'APP4' from dual union all  
  select 'APP5' from dual union all  
  select 'APP6' from dual union all  
  select 'APP7' from dual union all  
  select 'APP8' from dual union all  
  select 'APP9' from dual  
  </code></pre>
  
  <p>I need to get the string after the "Service Name:" string, put it between quotes, and place it into the select. 
  The first line must have the "x" after the string , and the last line must not contain the union all. There cannot be a space on the string. Since I don't have much experience with awk, so far I couldn't figure a way to do it.
  I have this so far:</p>
  
  <pre><code>srvctl config service -db database | grep 'Service name' | awk 'BEGIN {FS = "[:]"}  
  { gsub(/^[ \t]+|[ \t]+$/, "", $2)  
      if ( NR == 1 )  
      {  
           printf "'select\ \''" $2 "'\'\ x\ from\ dual\ union\ all\ '\n"  
      }  
      else  
      {  
          printf "'select\ \''" $2 "'\'\ from\ dual\ union\ all\ '\n"  
      }  
  }'  
  </code></pre>
  
  <p>It will generate the following output:</p>
  
  <pre><code>select 'APP1' x from dual union all  
  select 'APP2' from dual union all  
  select 'APP3' from dual union all  
  select 'APP4' from dual union all  
  select 'APP5' from dual union all  
  select 'APP6' from dual union all  
  select 'APP7' from dual union all  
  select 'APP8' from dual union all  
  select 'APP9' from dual union all 
  </code></pre>
  
  <p>Any help is appreciated</p>
  
  <p>Thanks</p>