按列的位置取数

【问题】

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每一行拆分成一个二维表。

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