title: Printing 3 character of each line in a file in bash shell
body: <p>I was solving one problem from one site, question is as follows:</p>
  
  <p>"Given N lines of input in a file, print the 3rd character from each line as a new line of output. It is guaranteed that each of the n lines of input will have a 3rd character."</p>
  
  <p>So to solve the problem I have written a command</p>
  
  <pre><code>while read -r line
  do 
        echo ${line:2:1}
  done &lt; sample.txt
  </code></pre>
  
  <p>Content in "sample.txt" is : </p>
  
  <pre><code>C.B - Cantonment Board/Cantonment
  C.M.C â€“ City Municipal Council
  C.T â€“ Census Town
  E.O â€“ Estate Office
  G.P - Gram Panchayat
  I.N.A â€“ Industrial Notified Area
  I.T.S - Industrial Township
  M â€“ Municipality
  M.B â€“ Municipal Board
  M.C â€“ Municipal Committee
  </code></pre>
  
  <p>I am getting output as follows:</p>
  
  <pre><code>B
  M
  T
  O
  P
  N
  T
  â
  B
  C
  </code></pre>
  
  <p>According to the site, the answer should be:</p>
  
  <pre><code>B
  M
  T
  O
  P
  N
  T
  в
  B
  C
  </code></pre>
  
  <p>Please not that 3rd last output is "в" and I am getting "â"
  I am new to the ascii, uts-8 conversion so not aware if this has any relation .</p>
  
  <p><strong>What should be change in the code to bring this answer?</strong> </p>