title: Compare two files given by xclip
body: <p>I am writing a diff parser for thunar but it is driving me mad.</p>
  <p>The full idea is in it is simplest to select two files right click on them and select the option compare, then the result of diff between the two files is parsed to xmessage. The simplest works nicely, but I also want to compare files from different locations, so the idea is to copy one or two files and then run diff over them.</p>
  <p>The great trouble is that I am not being able to format the output of xclip in order that diff could understand them (it reads the two lines as one filename)</p>
  <p>What I tried:</p>
  <pre><code>selected=&quot;$(xclip -selection clipboard -o)&quot;
  diff -qyr &quot;\&quot;${selected//$'\n'/\&quot; \&quot;}\&quot;&quot;
  
  n=0
  echo &quot;$selected&quot;| while read selection; do
      compare=&quot;$compare ${selection// /\ }&quot;
      diff -qyr ${compare}
      n=$(($n+1))
  done
  echo &quot;${compare[*]}&quot;
  echo xmessage diff: $(diff -qyr &quot;${compare[0]}&quot; &quot;${compare[1]}&quot;) 
  </code></pre>
  <p>I solved this before hitting post using tail and head:</p>
  <pre><code>file1=&quot;$(echo &quot;$selected&quot;|head -n1)&quot;
  file2=&quot;$(echo &quot;$selected&quot;|tail -n1)&quot;
  xmessage &quot;$(diff -qyr &quot;$file1&quot; &quot;$file2&quot;)&quot;
  </code></pre>
  <p>It was simpler than I thought, though why the more complicated solutions did not work?</p>