title: Find a string and extract values from result of hive query using shell script?
body: <p>Question Similar to :
  <a href="https://stackoverflow.com/questions/61352700/find-and-extract-value-after-specific-string-from-a-file-using-bash-shell-script">Find and Extract value after specific String from a file using bash shell script?</a></p>
  <p>I am executing a hive query from shell script and need to extract some value in a variable , query is as below :</p>
  <pre><code>sql=&quot;show create table dev.emp&quot;
  partition_col= `beeline -u $Beeline_URL -e $sql` | grep 'PARTITIONED BY' | cut -d &quot;'&quot; -f2`
  </code></pre>
  <p>output of sql query is below :</p>
  <pre><code>+----------------------------------------------------+
  |                   createtab_stmt                   |
  +----------------------------------------------------+
  | CREATE EXTERNAL TABLE `dv.par_kst`(                |
  |   `col1` string,                                   |
  |   `col2` string,                                  |
  |   `col3` string)                                  |
  | PARTITIONED BY (                                   |
  |   `part_col1` int,                                 |
  |   `part_col2` int)                                 |
  | ROW FORMAT SERDE                                   |
  |   'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe'  |
  | STORED AS INPUTFORMAT                              |
  |   'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat'  |
  | OUTPUTFORMAT                                       |
  |   'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' |
  | LOCATION                                           |
  |   'hdfs://nameservicets1/dv/hdfsdata/par_kst' |
  | TBLPROPERTIES (                                    |
  |   'spark.sql.create.version'='2.2 or prior',       |
  |   'spark.sql.sources.schema.numPartCols'='2',      |
  |   'spark.sql.sources.schema.numParts'='1',         |
  |   'spark.sql.sources.schema.part.0'='{&quot;type&quot;:&quot;struct&quot;,&quot;fields&quot;:[{&quot;name&quot;:&quot;col1&quot;,&quot;type&quot;:&quot;string&quot;,&quot;nullable&quot;:true,&quot;metadata&quot;:{}},{&quot;name&quot;:&quot;col2&quot;,&quot;type&quot;:&quot;string&quot;,&quot;nullable&quot;:true,&quot;metadata&quot;:{}},{&quot;name&quot;:&quot;col3&quot;,&quot;type&quot;:&quot;integer&quot;,&quot;nullable&quot;:true,&quot;metadata&quot;:{}},{&quot;name&quot;:&quot;part_col2&quot;,&quot;type&quot;:&quot;integer&quot;,&quot;nullable&quot;:true,&quot;metadata&quot;:{}}]}',  |
  |   'spark.sql.sources.schema.partCol.0'='part_col1', |
  |   'spark.sql.sources.schema.partCol.1'='part_col2', |
  |   'transient_lastDdlTime'='1587487456')            |
  +----------------------------------------------------+
  </code></pre>
  <p>from above sql,  I want to extract PARTITIONED BY details.</p>
  <pre><code>Desired output :
  
  part_col1 , part_col2
  </code></pre>
  <p>tried with below code but not getting correct value :</p>
  <pre><code>partition_col=`beeline -u $Beeline_URL -e $sql` | grep 'PARTITIONED BY' | cut -d &quot;'&quot; -f2`
  </code></pre>
  <p>and these PARTITIONED BY is not fixed , means for some other file it might contains 3 or more , so I want extract all the PARTITIONED BY.</p>
  <p>All the values between PARTITIONED BY and ROW FORMAT SERDE , removing spaces &quot;`&quot; and data types!</p>