Question Locked

unix script to read comma delimited file .

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

comma delimited file as follows

name,place,number
sofia,canada,8899
william,alaska,8899
smit,london,4555
..
..

template file as follows.
---
---
---

I need to read the data from delimited file line by line and for each line read create new template file with data in the blanks .

at the end i need to have 3 newtemplate files
with appropriate data in it .
eg : tempelatefile 1
sofia
canada
8899
so on tempelate file 2 and 3

need a unix script to perform the task .

2 replies

by marv732

Create a file pdata.awk containing

BEGIN{
nm=""
pl=""
nbr=""
}
{
{
fname="template"NR".txt";
printf("%s%s%s\n%s%s%s\n%s%s%s",nm,$1,nm,pl,$2,pl,nbr,$3,nbr) > fname;
}
}

Then from the command prompt
awk -F, -f pdata.awk pdata.txt
where pdata.txt is the comma delimited file.

This creates a series of files called templatex.txt where x is a number

HTH
Greg

This discussion is closed to new replies.