how can i print the column in text file to row wise using unix command?
I have file like this.. for eg:
number,dac,amountdac,expdate,0
1111,1,0.000000,2010-07-21,0
1111,2,0.000000,2010-07-21,0
1111,3,0.000000,2010-07-21,0
1111,4,0.000000,2010-07-21,0
1111,5,0.000000,2010-07-21,0
1111,6,0.000000,2010-07-21,0
1111,7,0.000000,2010-07-21,0
1111,8,0.000000,2010-07-21,0
1111,9,0.000000,2010-07-21,0
1111,10,0.000000,2010-07-21,0
2222,1,50.000000,2010-07-21,0
2222,2,0.000000,2010-07-21,0
2222,3,0.000000,2010-07-21,0
2222,4,0.000000,2010-07-21,0
2222,5,0.000000,2010-07-21,0
2222,6,0.000000,2010-07-21,0
2222,7,0.000000,2010-07-21,0
2222,8,10.000000,2010-07-21,0
2222,9,0.000000,2010-07-21,0
2222,10,0.000000,2010-07-21,0
3333,1,0.000000,2010-07-21,0
3333,2,0.000000,2010-07-21,0
3333,3,0.000000,2010-07-21,0
3333,4,0.000000,2010-07-21,0
3333,5,0.000000,2010-07-21,0
3333,6,0.000000,2010-07-21,0
3333,7,0.000000,2010-07-21,0
3333,8,0.000000,2010-07-21,0
3333,9,200.000000,2010-07-21,0
3333,10,50.000000,2010-07-21,0
i want output like this, column 1 number is same for all dac1 to dac10. header i gave for your reference. in original file i don't have header.
number,dac1,dac2,dac3,dac4,dac5,dac6,dac7,dac8,dac9,dac10,amountdac1,amountdac2,amountdac3,,amountdac4,amountdac5,amountdac6,amountdac7,amountdac8,amountdac9,,amountdac10,expdate1,expdate2,expdate3,expdate4,expdate5,expdate6,expdate7,expdate8,expdate9,expdate10,0
1111,1,2,3,4,5,6,7,8,9,10,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,0
2222,1,2,3,4,5,6,7,8,9,10,50.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,10.000000,0.000000,0.000000,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,0
3333,1,2,3,4,5,6,7,8,9,10,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,200.000000,50.000000,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21开发者_JAVA百科,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,0
awk -F"," '{
a[$1];
b[$1]=b[$1]","$2
c[$1]=c[$1]","$3
d[$1]=d[$1]","$4
e[$1]=e[$1]","$5 }
END{ for(i in a){ print i,b[i],c[i],d[i],e[i] } } ' file
You could write a python script to break that up:
numbers = []
dacs = []
amountdacs = []
expdates = []
for row in text:
number, dac, amountdac, expdate, zero = row.split(',')
numbers.append(number)
dacs.append(dac)
amountdacs.append(amountdac)
expdates.append(expdate)
# print things out however you want them
You could probably do something similar in perl, if you're more facile with it than I am.
Basically the idea is i suppose u need to transpose the data. stackoverflow has a similar question with a very good solution
only task left is u need to use your scripting skills to
- take the chunk of data i.e., 10 rows at a time.
- remove the first column in that 10 rows and transpose the data
- add the first column value (here 1111 or 2222 or 3333)
all the above 3 steps should be done recursively for all the rows in the input file.
I guess half of the solution is provided and you can manage the remaining over here with simple scripting.
精彩评论