title: Read user given file character by character in bash
body: <p>I have a file which is kind of unformatted, I want to place a new-line after every 100th character and remove any other new lines in it so that file may look with consistent width and readable</p>
  
  <p>This code snippet helps read all the lines</p>
  
  <pre><code> while read LINE
          do
                  len=${#LINE}
                  echo "Line length is : $len"
          done &lt; $file
  </code></pre>
  
  <p>but how do i do same for characters</p>
  
  <p>Idea is to have something like this : (<em>just an example, it may have syntax errors, not implemented yet</em>)</p>
  
  <pre><code> while read ch  #read character
    do
           chcount++ # increment character count
  
      if [ "$chcount" -eq "100" &amp;&amp; "$ch"!="\n" ] #if 100th character and is not a new line
      then
          echo -e "\n" #echo new line
      elif [ "$ch"=="\n" ]  #if character is not 100th but new line
          then
          ch=" " $replace it with space
       fi
    done &lt; $file
  </code></pre>
  
  <p>I am learning <code>bash</code>, so please go easy!!</p>