Sunday, January 3, 2016

How to Read CSV File using shell script





 

 Parse through CSV(Comma -separated File ) using shell script



For that You need to know What is CSV File ?

  • First of all Full Name of CSV is comma-separated values.
  • A CSV stores tabular data (numbers and text) in plain text.  
  • Each line of the file is a data record And Each record consists of one or more fields, separated by commas.
  • The use of the comma as a field separator is the source of the name for this file format.
  • An official standard for the CSV file format does not exist Yet.
  •  In popular usage, however, the term CSV may denote some closely related delimiter-separated formats, which use a variety of different field delimiters. These include tab-separated values and space-separated values, both of which are popular. Such files are often even given a .csv extension, despite the use of a different field separator than the comma. This loose terminology creates problems for data exchange.
  • We can use any separator separate the fields of each and every Record.

    CSV File  :-
 

  
Read CSV File Using Shell Script :- 

        #!/bin/bash
       INPUT='demo.csv'

         [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
        
        While IFS=',' read -r No Name Contact_number  

        # IFS Stands for Internal Field Separator
 
        do
               echo "$No $Name $Contact_number"

        done < "$INPUT"

Output :-  


For Further Knowledge Related to Linux stay tuned with visionfortech.blogspot.com.
Thanks.

No comments:

Post a Comment

Protected by Copyscape