Sunday, October 17, 2010

Bash Script to process csv

Task: To process the login id and Name using CSV, and this is only a 2 column csv.

example csv

#/$HOME/file1.txt
juan.delacruz,Juan Dela Cruz
pnoy.aquino,Ninoy Aquino
ohbet.gomez,Ohbet Gomez
#eof

#Script
#!/bin/bash
#
#
#
while IFS=, read login name
do
echo NAME:$name and LOGIN ID: $login
done < /$HOME/testtxt2
#eof



Note: IFS=, where "," is the delimiter (of course, its a csv :P)


#Output
[xxx@localhost ~]$ bin/test3.sh
NAME:Juan Dela Cruz and LOGIN ID: juan.delacruz
NAME:Ninoy Aquino and LOGIN ID: pnoy.aquino
NAME:Ohbet Gomez and LOGIN ID: ohbet.gomez