![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| create filename with 'DD/MM/YYYY' date format | royalibrahim | Shell Programming and Scripting | 4 | 04-12-2008 08:24 AM |
| To convert multi format file to a readable ascii format | gaur.deepti | UNIX for Dummies Questions & Answers | 5 | 03-25-2008 03:03 PM |
| How to create concatenate a file in tab format | ahjiefreak | UNIX for Dummies Questions & Answers | 12 | 12-11-2007 08:22 PM |
| Convert UTF8 Format file to ANSI format | rajreddy | UNIX for Dummies Questions & Answers | 9 | 05-25-2007 08:26 AM |
| Convert UTF8 Format file to ANSI format | rajreddy | UNIX for Advanced & Expert Users | 1 | 05-24-2007 06:40 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help to Create this file format structure
This data comes form the table and exported into the file in this format
File1 Format weboffercode1,sourcecode1,1,1,1,1,1,1 weboffercode1,sourcecode2,1,1,1,1,1,1 weboffercode1,sourcecode1,1,1,1,1,1,1 weboffercode1,sourcecode3,1,1,1,1,1,1 weboffercode1,sourcecode3,1,1,1,1,1,1 weboffercode2,sourcecode1,1,1,1,1,1,1 weboffercode2,sourcecode1,1,1,1,1,1,1 weboffercode2,sourcecode2,1,1,1,1,1,1 weboffercode3,sourcecode1,1,1,1,1,1,1 weboffercode3,sourcecode2,1,1,1,1,1,1 I have to format this file in the following format as :- File2 : sum of the field f3,f4,f5,f6,f7,f8 for same WebOfferCode and Source code combination weboffercode1,sourcecode1,2,2,2,2,2,2 weboffercode1,sourcecode2,1,1,1,1,1,1 weboffercode1,sourcecode3,2,2,2,2,2,2 sum of fields f3,f4,f5,f6,f7,f8 for same WebOfferCode TOTAL, weboffercode1,5,5,5,5,5,5 sum of the field f3,f4,f5,f6,f7,f8 for same WebOfferCode and Source code combination weboffercode2,sourcecode1,2,2,2,2,2,2 weboffercode2,sourcecode2,1,1,1,1,1,1 sum of fields f3,f4,f5,f6,f7,f8 for same WebOfferCode TOTAL, weboffercode1,3,3,3,3,3,3 sum of the field f3,f4,f5,f6,f7,f8 for same WebOfferCode and Source code combination weboffercode3,sourcecode1,1,1,1,1,1,1 weboffercode3,sourcecode2,1,1,1,1,1,1 sum of fields f3,f4,f5,f6,f7,f8 for same WebOfferCode TOTAL, weboffercode2,2,2,2,2,2,2 So that if I save this file2.csv it is in the format of the picture as shown above.Let me know how can I do the operations on File1 to create such file format as File2…Primarily I was to know how to write a script to add the data present in the file column wise. |
|
||||
|
Code:
nawk 'BEGIN{FS=","}
{
a[$1$2]=$3+a[$1$2]
b[$1$2]=$4+b[$1$2]
c[$1$2]=$5+c[$1$2]
d[$1$2]=$6+d[$1$2]
e[$1$2]=$7+e[$1$2]
f[$1$2]=$8+f[$1$2]
A[$1]=$3+A[$1]
B[$1]=$3+B[$1]
C[$1]=$3+C[$1]
D[$1]=$3+D[$1]
E[$1]=$3+E[$1]
F[$1]=$3+F[$1]
if(t[$1]=="")
t[$1]=$2
else if (index(t[$1],$2)==0)
t[$1]=sprintf("%s,%s",t[$1],$2)
}
END{
for (i in A)
{
tt=split(t[i],temp,",")
for (j=1;j<=tt;j++)
{
p=sprintf("%s%s",i,temp[j])
print i","p","a[p]","b[p]","c[p]","d[p]","e[p]","f[p]
}
print "TOTAL,"i","A[i]","B[i]","C[i]","D[i]","E[i]","F[i]
}
}' filename
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|