<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 5/13/2013 4:00 PM, Glenn Harris
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAOO-jWtiH2m4NziPJs9Dmx6Cu7GvNBN_pkTetjqzWqjj+6j_tA@mail.gmail.com"
      type="cite">
      <div dir="ltr">On Mon, May 13, 2013 at 11:33 AM, Drew Tomlinson <span
          dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:drew@mykitchentable.net" target="_blank">drew@mykitchentable.net</a>&gt;</span>
        wrote:<br>
        <div class="gmail_extra">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">After
              upgrading from 0.24 to 0.26, all my commflag jobs exited
              on error 140. &nbsp;After learning that it was because of the
              commflag command and fixing that in the general setup, I
              wanted to commflag all the recordings that had erred.
              &nbsp;With some reading and fiddling, I came up with this:<br>
              <br>
              mysql mythconverg -umythtv -pmythtv &lt; ~/commflag.sql |
              sed '1d; s/-//g;s/://g' | awk '{print
              "/usr/bin/mythcommflag --queue --chanid", $1,
              "--starttime",$2$3}'<br>
              <br>
              Commflag.sql contains:<br>
              SELECT chanid, starttime FROM
              `mythconverg`.`recorded`where commflagged &lt;&gt; 1;<br>
              <br>
              Which prints this:<br>
              <br>
              /usr/bin/mythcommflag --queue --chanid 2581 --starttime
              20130513045900<br>
              /usr/bin/mythcommflag --queue --chanid 1278 --starttime
              20130513045900<br>
              /usr/bin/mythcommflag --queue --chanid 3031 --starttime
              20130509045900<br>
              <br>
              So I added a 'for' loop with a 'do echo' to test:<br>
              <br>
              for i in "`mysql mythconverg -umythtv -pmythtv &lt;
              ~/commflag.sql | sed '1d; s/-//g;s/://g' | awk '{print
              "/usr/bin/mythcommflag --queue --chanid", $1,
              "--starttime",$2$3}'`"<br>
              <br>
              do<br>
              <br>
              &nbsp; &nbsp; &nbsp; &nbsp; echo ${i}<br>
              <br>
              done<br>
              <br>
              <br>
              But the output is just one long line:<br>
              <br>
              /usr/bin/mythcommflag --queue --chanid 2581 --starttime
              20130513045900 /usr/bin/mythcommflag --queue --chanid 1278
              --starttime 20130513045900 /usr/bin/mythcommflag --queue
              --chanid 3031 --starttime 20130509045900<br>
              <br>
              I've read up on 'awk' and tried adding '\n' but this
              doesn't seem to have any effect. &nbsp;I've also read about
              $IFS and tried setting that to '\n' but still no help.<br>
              <br>
              Thus I have these questions:<br>
              <br>
              1. Is a 'for' loop the proper loop to use? &nbsp;I fiddled with
              'while' and 'read' and 'read line' but couldn't get those
              to work either.<br>
              <br>
              2. How do I get the newline added so I can make this a
              script?<br>
              <br>
              3. Am I duplicating something that already exists in
              MythTV?<br>
              <br>
              Thanks for your time.<br>
              <br>
              Cheers,<br>
              <br>
              Drew<br>
            </blockquote>
            <div><br>
            </div>
            <div style="">I use something like this to get at mysql
              results in bash:</div>
            <div><br>
            </div>
            <div><br>
            </div>
            <div style="">current_line=0</div>
            <div style=""># read query results into $data, one line at a
              time<br>
            </div>
            <div>mysql --user=$MYSQLUSER --password=$MYSQLPASSWORD
              $MYSQLDB &lt; myquery.sql | while read -r data</div>
            <div>do</div>
            <div>&nbsp; &nbsp; current_line=$(($current_line+1))</div>
            <div>&nbsp; &nbsp; IFS=' &nbsp; &nbsp; &nbsp; ' # tab as separator</div>
            <div>&nbsp; &nbsp; line=(${data//NULL/0}) # replace NULL with a more
              useful value, split $data into an array using IFS</div>
            <div>&nbsp; &nbsp; unset IFS # back to default</div>
            <div><br>
            </div>
            <div style="">&nbsp; &nbsp; # $line contains the current 'record' as
              an array</div>
            <div style="">&nbsp; &nbsp; echo "$current_line -&gt; ${line[0]} -
              ${line[1]}"</div>
            <div style="">done<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Thank you for the example.&nbsp; I'll play around with that just to learn
    more about scripting.<br>
    <br>
    Cheers,<br>
    <br>
    Drew<br>
    <pre class="moz-signature" cols="72">-- 
Like card tricks?

Visit The Alchemist's Warehouse to 
learn card magic secrets for free!

<a class="moz-txt-link-freetext" href="http://alchemistswarehouse.com">http://alchemistswarehouse.com</a></pre>
  </body>
</html>