Creating a csv file based on Existing file

Hi I am Newbie to Unix.Appreciate Help from forum

user would loada b.Csv File(Below example) in /data/m/ directory.Program need to read the b.csc to extract certain column and create a new file /data/d/ directory as csv file with new name.

User File Format

1232,samshouston,12345 houston,56666,20030811,78576,5,EA,789,SHELL
1456,dellshouston,2222 houston, 5644666,20030811,78576,5,EA,789,dell

need to extract column1,column3,column4,column5,column7
and one more condition if the column4 length is lessthan 6 then add 000 before

output wil look like in /data/o/tran.csv

1232,12345 houston,00056666,20030811,78576
1456,2222 houston,5644666,20030811,78576

Appreciate your help

thanks

Skyway

Thats quite straightforward. Find a script skeleton below:

#! /bin/ksh
typeset    fInput="/data/m/b.csc"      # input filename
typeset    fOutput="/data/o/tran.csv"  # output filename

if [ -r "$fInput" ] ; then     # perhaps there should be more input validation
     print -u2 "unable to read input file"
     exit 1
fi

sed 's/^\([^,]*,[^,]*,[^,]*,\)\([0-9]\{1,5\}\),/\1000\2/
     s/^\([^,]*,\)[^,]*,\([^,]*,[^,]*,[^,]*,\)[^,]*,\([^,]*\).*$/\1\2\3/' $fInput > $fOutput

exit $?

Hope this helps.

bakunin

Or with awk:

awk -F, '{printf("%s,%s,%s,%0.8d,%s,%s\n", $1,$3,$4,$5,$6,$7)}' infile > outfile

Regards

I really Appreciate immediate Replyt.I am Going to Try both methods Today

thanks

Skyway