Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

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 :- 


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

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

        done < "$INPUT"

Output :-  

For Further Knowledge Related to Linux stay tuned with

Tuesday, November 3, 2015

Solution of Bad Interpreter Error in Linux

Solution for Bad Interpreter Error in Linux are as follow.

If you write a shell Script of linux in windows OS the when you try to execute that script in linux then it comes up with the bin/bash or Bad Interpreter Error.

Error :-
          Bin/Bash or Bad Interpreter

Solution for that
        Execute that script with Following Command
          perl -p -i -e "s/\r//g" <file name>
And then try to Execute File.
It will Execute the File.
Protected by Copyscape