title: Using output piped from sed
body: <p>I have a sed command that is capturing a single line with sometext. The line in the file it is capturing ends with a linefeed. I am trying to utilize this variable in a pipeline, however, when I attempt to echo, or use it with other commands requiring an input, the result is a blank. Ex:
  <code>sed '1,1!d' somefile.txt | echo "$1"</code>,  I know the variable itself is not empty as I can replace <code>echo "$1"</code> with <code>cat $1</code> and see the correct printout. </p>
  
  <p>edit - I have tried piping to a tr -d and removing the newline. I have confirmed the newline character is gone, yet echos still show blank. Cats do not.</p>
  
  <p>edit 2 - I piped the variable into an if statement <code>... | if [[ -z $1 ]]; then cat $1; fi</code> it hits the if, is determined to be empty, so runs the cat, which prints a non-empty line to console. If the variable is empty why is cat still printing out information?</p>
  
  <p>What is causing this inconsistency and how can I solve my problem? The ultimate goal is to run the output of one sed, through another to replace specific lines in a target file.</p>
  
  <p><code>sed '1,1!d' somefile.txt | sed '2,1s/.*/'$1'/' targetfile.txt</code></p>
  
  <h2> Contents of somefile.txt:</h2>
  
  <pre><code>these
  are
  words
  </code></pre>
  
  <h2> Contents of targetfile.txt:</h2>
  
  <pre><code>The next line should say these
  This line should say these
  The previous line should say these
  </code></pre>
  
  <p>Output of echo after sed:</p>
  
  <pre><code>&lt;empty&gt;
  </code></pre>
  
  <p>Output of cat after sed:</p>
  
  <pre><code>these
  </code></pre>
  
  <p>Output of 2nd sed, using input from 1st: </p>
  
  <pre><code>The next line should say these
  
  the previous line should say these
  </code></pre>