title: Bash Script to generate csv file from text
body: <p>I have a text file with records:</p>
  
  <pre><code>  Data1
  
    Data2
  
    ...
  
    Data50
  </code></pre>
  
  <p>I have to create a .csv file from the above text file in the following format:</p>
  
  <pre><code>Type |  Count | Name
  
  Def |    u1 |    Data1
  
  Def |    u2  |     Data2
  
  ....  |  .....   |  ....
  
  Def  |   u50   | Data50
  </code></pre>
  
  <p>i need a bash script to generate the .csv file from the text file. I am new to shell scripting! I have gone through basics of awk and sed as well. 
  I have a vague idea like:</p>
  
  <pre><code>#!/bin/bash
  type="Def"
  x=1
  count="u"
  for F in ../test.txt
  do
      {
         read \n
         echo "$type, $count$x, $..." &gt;&gt; ../test.csv
         x=x+1
      } &lt; $F
  
  done 
  </code></pre>
  
  <p>I do understand that the field separator is '\n'. I am kind of lost after that. </p>
  
  <p>Thanks!</p>