title: Copy files based on content
body: <p>Need to find all files in specific subdirectories ending in <code>.xml</code>. They'll either be in <code>.../etc/apps/&lt;dirname&gt;/local/data/ui/views/*.xml</code> or <code>.../etc/apps/&lt;dirname&gt;/default/data/ui/views/*.xml</code>.
  If the file in <code>/etc/apps/&lt;dirname&gt;/default/data/ui/views/*.xml</code> doesn't have the string <code>version=&quot;1.1&quot;</code> in the first line, copy the file to the local directory as the same file name, add that string to the first line and quit.</p>
  <p>I'm stuck on copying the file from its default dir to its local dir.
  I've got:</p>
  <pre class="lang-bash prettyprint-override"><code>src=.../etc/apps/*/default/data/ui/views/*.xml
  dest=.../etc/apps/*/local/data/ui/views/
  pat='version='
  for file in $src
  do
      if [[ &quot;$(sed -n '1{/version=/p};q' &quot;$file&quot;)&quot; ]]; then
          awk 'NR==1 {print; exit}' &quot;$file&quot;
          echo &quot;No change necessary to $file&quot;
      else
          echo &quot;Copying $file to local ../local/data/ui/views/$file and running sed '1 s/&gt;/ version=&quot;1.1&quot;&gt;/'&quot;
      fi
  done
  </code></pre>
  <p>Which won't work because it's going to use the whole path for $file like I told it to.
  I get the feeling I'm overthinking this. But I'm not sure where to go from here.</p>