按列的位置取数

【问题】

I have a text file which has all the information I need in lines and this needs to be converted into a .csv file.

Example:

abbccccdeffffiiiiiiiiiiiiiijjkkkkkkkkkkkllmmmmmmnnooo
abbccccdeffffiiiiiiiiiiiiiijjkkkkkkkkkkkllmmmmmmnnooo
abbccccdeffffiiiiiiiiiiiiiijjkkkkkkkkkkkllmmmmmmnnooo
abbccccdeffffiiiiiiiiiiiiiijjkkkkkkkkkkkllmmmmmmnnooo
abbccccdeffffiiiiiiiiiiiiiijjkkkkkkkkkkkllmmmmmmnnooo
abbccccdeffffiiiiiiiiiiiiiijjkkkkkkkkkkkllmmmmmmnnooo

So basically

  • 1.“a” is first column with just one char
  • 2.“bb” is second column with length 2
  • 3.“cccc” is third column with length 4
  • 4.“d” is fourth column with length 1
  • 5.“e” is fifth column with length 1
  • 6.“ffff” is sixth column with length 4

As we can see from this example, I cannot use a delimiter with space or commas, they are all of different lengths. Please point me to the right direction. I just need an idea of how to approach to this problem.

【回答】

按列取记录可用SPL实现,代码简单易懂:

A
1=file("d:\\source.csv").import@si()
2=A1.new(mid(~,1,1),mid(~,2,2),mid(~,4,4),mid(~,8,1),mid(~,9,1),mid(~,10,4))

A1:读取source.csv文件内容。

A2:使用mid(s, start{, len})函数获取字符串的子串     ,以便把A1每一行拆分成一个二维表。

计算结果是二维表,可以继续进行排序、查询,或分组汇总等运算。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值