The following KSH script read the contents of a text file in CSV format , calculate its sum line by line and write the result to another file.
#!/usr/bin/ksh
#PROGRAM BEGINS HERE
#DEFINING OUTPUT FILE
OUTPUTFILE=result.txt;
#CHECK FOR INPUT FILE
if [[ $# -eq 0 ]];then
print "No Files";
exit
fi;
#ACCEPTING INPUT FILE IF PRESENT
FILE=$1;
#READ FILE CONTENT LINE BY LINE
while read FILE
do
VAR1=`echo $FILE| cut -d "," -f1`;
VAR2=`echo $FILE|cut -d "," -f2`;
SUM=`expr $VAR1 + $VAR2`;
echo $SUM >> $OUTPUTFILE;
done < "$FILE"
#PROGRAM ENDS HERE
Comments
Post a Comment