title: replacing multiple lines in shell script with only one output file
body: <p>I have one file <code>Length.txt</code> having multiples names (40) line by line. 
  I want to write a small shell script where it will count the character count of each line of the file and if the count is less than 9 replace those lines with adding extra 8 spaces and 1 at the end of each line. </p>
  
  <p>For example, if the name is</p>
  
  <pre><code>XXXXXX
  </code></pre>
  
  <p>replace as</p>
  
  <pre><code>XXXXXX        1
  </code></pre>
  
  <p>I tried with the below coding. It is working for me, however whenever it's replacing the line it is displaying all the lines at a time.
  So suppose I have 40 lines in <code>Length.txt</code> and out of that 4 lines having less than 9 character count then my output has 160 lines.
  Can anyone help me to display only 40 line output with the 4 changed lines?</p>
  
  <pre><code>#!/usr/bin/sh
  #set -x
  
  while read line;
  do
  count=`echo $line|wc -m`
          if [ $count -lt 9 ]
          then
          Number=`sed -n "/$line/=" Length.txt`;
          sed -e ""$Number"s/$line/$line       1/" Length4.txt
          fi
  done &lt; Length.txt
  </code></pre>