title: bash script append text to first line of a file
body: <p>I want to add a text to the end of the first line of a file using a bash script.
  The file is /etc/cmdline.txt which does not allow line breaks and needs new commands seperated by a blank, so text i want to add realy needs to be in first line.</p>
  
  <p>What i got so far is:</p>
  
  <pre><code>line=' bcm2708.w1_gpio_pin=20'
  file=/boot/cmdline.txt
  if ! grep -q -x -F -e "$line" &lt;"$file"; then
    printf '%s' "$line\n" &gt;&gt;"$file"
  fi
  </code></pre>
  
  <p>But that appends the text after the line break of the first line, so the result is wrong.
  I either need to trim the file contend, add my text and a line feed or somehow just add it to first line of file not touching the rest somehow, but my knowledge of bash scripts is not good enough to find a solution here, and all the examples i find online add beginning/end of every line in a file, not just the first line.</p>