本帖最后由 keke00 于 2010-09-26 21:54 编辑
请教如何删除重复列?
个人思路:前5行删除橙色标记的列,后5行删除绿色标记列,
最后在第一列位置插入橙色和绿色标记的列
想用awk来实现,
大家看看我自己写的,免去考虑匹配问题,复杂啦点,求犀利版- awk -F, 'NR<=5{printf $1;for(i=1;i<=NF;i=i+3){printf",";printf $(i+1);printf",";printf $(i+2)}printf"\n"}NR>5{for(i=0;i<=NF;i=i+3){printf",";printf $(i+1);printf",";printf $(i+2)}printf"\n"}' 123.csv
复制代码 或者其它思路?
如下图:
原始数据:- ,H1,,,H2,,,H3,,,H4,
- A,8,20%,A,8,30%,A,8,20%,A,8,20%
- B,6,30%,B,6,20%,B,6,30%,B,6,30%
- C,5,10%,C,5,40%,C,5,10%,C,5,10%
- D,3,40%,D,3,10%,D,3,40%,D,3,40%
- R1,10,,R2,10,,R3,10,,R4,10,
- C1,6,,C2,6,,C3,6,,C4,6,
- R2,2,,R3,2,,R4,2,,R5,2,
- C2,-2,,,,,C4,-2,,C5,-2,
- R3,-6,,,,,R5,-6
- C3,-10,,,,,C5,-10
复制代码 整理后数据:- ,H1,,H2,,H3,,H4
- A,8,20%,8,30%,8,20%,8,20%
- B,6,30%,6,20%,6,30%,6,30%
- C,5,10%,5,40%,5,10%,5,10%
- D,3,40%,3,10%,3,40%,3,40%
- ,R1,10,R2,10,R3,10,R4,10
- ,C1,6,C2,6,C3,6,C4,6
- ,R2,2,R3,2,R4,2,R5,2
- ,C2,-2,,,C4,-2,C5,-2
- ,R3,-6,,,R5,-6
- ,C3,-10,,,C5,-10
复制代码 |