这是一个强大的处理格式化文本的工具,通过使用其脚本,几乎可以把文本当作数据库处理


分隔符为逗号, 标尺格式化显示各个字段
gawk  -F"," "{printf \"%-6s %-9s %-9s %-9s %-9s\n\", NR, $1, $2, $4, $12}"   aStockList.csv 
如:
1         代码      名称      现价      今开    
2         000001    深发展A  40.45     40.7    
3         000002    万  科A  35.8      35.69   
4         000004    ST 国 农  9.72      9.91    
5         000005    ST 星 源  0         ---     
6         000006    深振业A  33.3      33.31   
7         000007    ST 达 声  7.18      7.1     
8         000008    *ST 宝投  0         ---     
9         000009    S深宝安A  13.59     13.6    
10        000010    S ST华新  0         ---     


取文件最后一行的行号.实际就是取总行数
gawk "END {print NR}"  aStockList.csv  



将数据分类汇总
gawk -F"," "{pos=(NR-1)%40; page=int((NR-1)/40); a=int((NR-1)/600) }
    {print $1\",\",$2\",\",pos\",\",page\",\",a}"  aStockList.csv |
  gawk -F"," "BEGIN
       { printf \"%-6s %-9s %-9s  %-4s\n\", \"  \", \"代码\", \"名称\", \"条/页/位置\";
         print \"----------------------------------\"  }
       { printf\"%-6s %-9s %-9s %-4s \n\", NR, $1, $2, $5\"/\"$4%15\"/\"$3}"


原始数据:
代码   ,名称,涨幅%%,现价,日涨跌,买入价,卖出价,总量,现量,涨速%%,换手%%,今开
000001,深发展A,-0.32,40.45,-0.54,40.45,40.48,90119,32,0.24,0.58,40.7
000002,万  科A,-0.56,35.8,-0.2,35.79,35.8,172067,3,0.56,0.33,35.69
000004,ST 国 农,-1.82,9.72,-0.18,9.7,9.72,18424,8,0,2.82,9.91
000005,ST 星 源,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000006,深振业A,0,33.3,0,33.22,33.3,8753,6,0.27,0.4,33.31
000007,ST 达 声,2.43,7.18,0.17,7.15,7.18,11955,2,0.7,0.83,7.1
000008,*ST 宝投,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000009,S深宝安A,-1.02,13.59,-0.14,13.59,13.6,31747,150,0.22,0.55,13.6
000010,S ST华新,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000011,S深物业A,-0.86,12.65,-0.11,12.6,12.65,1608,24,0.39,0.18,12.43
000012,南  玻A,0.17,18.16,0.03,18.16,18.18,32715,149,0.66,0.85,18
000014,沙河股份,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000016,深康佳A,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000017,S ST中华,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000018,ST中冠A,-0.39,7.66,-0.03,7.66,7.67,1182,2,0.13,0.28,7.69
000019,深深宝A,-2.81,17.3,-0.5,17.3,17.38,12168,9,0.69,1.66,17.6
000020,ST华发A,-0.14,6.91,-0.01,6.86,6.91,3235,6,0,0.5,6.91
000021,长城开发,-1.97,15.39,-0.31,15.38,15.39,18408,3,0.39,0.5,15.68
000022,深赤湾A,-3.59,24.45,-0.91,24.45,24.46,5446,9,0.16,0.46,25.18
000023,深天地A,-1.79,10.41,-0.19,10.4,10.41,3878,17,-0.19,0.58,10.78
000024,招商地产,-3.42,87.7,-3.11,87.71,87.99,2213,51,-0.11,0.07,91.9
000025,特  力A,-1.48,13.99,-0.21,13.95,13.99,6856,4,-0.07,1.43,14.18
000026,飞亚达A,-3.49,11.6,-0.42,11.6,11.65,20177,3,0.6,2.54,11.9
000027,深能源A,-0.23,21.3,-0.05,21.28,21.3,30689,5,0.37,0.51,21.4
000028,一致药业,-1.35,15.38,-0.21,15.31,15.38,6399,3,0.32,0.57,15.58
000029,深深房A,-1.21,7.36,-0.09,7.35,7.36,16261,7,1.51,0.6,7.49
000030,S*ST盛润,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000031,中粮地产,0.89,27.29,0.24,27.28,27.29,46135,78,0.25,0.94,27.05
000032,深桑达A,-2.2,11.1,-0.25,11.07,11.1,5361,50,0.18,0.47,11.31
000033,新都酒店,-1.94,6.07,-0.12,6.06,6.07,19441,5,0.66,1.23,6.13
000034,SST 深泰,-0.48,8.24,-0.04,8.24,8.27,3797,15,0.12,0.45,8.21
000035,ST 科 健,--- ,0,--- ,--- ,--- ,0,0,--- ,0,---
000036,华联控股,1.28,7.91,0.1,7.9,7.91,97065,300,0.5,1.26,7.73
000037,深南电A,-1.9,8.25,-0.16,8.24,8.25,8874,62,0.24,0.55,8.4
000039,中集集团,-1.41,23.7,-0.34,23.7,23.72,55243,9,0.21,0.59,24.05
000040,深 鸿 基,-1.96,8.02,-0.16,8.01,8.02,24508,10,0.62,0.62,8.2
000042,深 长 城,-1.42,23.66,-0.34,23.66,23.7,3064,4,0.25,0.23,24.1
000043,深南光A,1.83,23.9,0.43,23.85,23.9,1543,11,0.42,0.17,23.53
000045,深纺织A,-1.88,7.31,-0.14,7.31,7.36,3779,5,-0.67,0.81,7.45
000046,泛海建设,-0.32,59.89,-0.19,59.89,59.9,4754,4,-0.01,0.21,60.11
000048,*ST 康达,-0.95,5.2,-0.05,5.2,5.22,11110,2,0,0.5,5.27
000049,德赛电池,2.26,10.86,0.24,10.85,10.86,8425,44,0.09,1.33,10.62
000050,深天马A,-0.66,13.58,-0.09,13.56,13.58,10580,4,0.36,0.88,13.76
000055,方  大A,-1.48,7.32,-0.11,7.32,7.33,7959,5,0.68,0.67,7.47
000056,深 国 商,-2.46,11.1,-0.28,11.12,11.19,5911,8,0.45,0.6,11.38
000058,*ST 赛格,-0.21,9.64,-0.02,9.63,9.64,25708,60,-0.41,1.22,9.87
000059,辽通化工,0.27,11.32,0.03,11.31,11.32,62685,28,0.17,1.9,11.32
000060,中金岭南,2.16,47.2,1,47.18,47.2,135188,3,1.17,3.13,46.19



目标数据:
       代码      名称       条/页/位置
----------------------------------
1      000001     深发展A  0/0/ 0
2      000002     万  科A  0/0/ 1
3      000004     ST 国 农  0/0/ 2
4      000005     ST 星 源  0/0/ 3
5      000006     深振业A  0/0/ 4
6      000007     ST 达 声  0/0/ 5
7      000008     *ST 宝投  0/0/ 6
8      000009     S深宝安A  0/0/ 7
9      000010     S ST华新  0/0/ 8
10     000011     S深物业A  0/0/ 9
11     000012     南  玻A  0/0/ 10
12     000014     沙河股份  0/0/ 11
13     000016     深康佳A  0/0/ 12
14     000017     S ST中华  0/0/ 13
15     000018     ST中冠A  0/0/ 14
16     000019     深深宝A  0/0/ 15
17     000020     ST华发A  0/0/ 16
18     000021     长城开发  0/0/ 17
19     000022     深赤湾A  0/0/ 18
20     000023     深天地A  0/0/ 19
21     000024     招商地产  0/0/ 20
22     000025     特  力A  0/0/ 21
23     000026     飞亚达A  0/0/ 22
24     000027     深能源A  0/0/ 23
25     000028     一致药业  0/0/ 24
26     000029     深深房A  0/0/ 25
27     000030     S*ST盛润  0/0/ 26
28     000031     中粮地产  0/0/ 27
29     000032     深桑达A  0/0/ 28
30     000033     新都酒店  0/0/ 29
31     000034     SST 深泰  0/0/ 30
32     000035     ST 科 健  0/0/ 31
33     000036     华联控股  0/0/ 32
34     000037     深南电A  0/0/ 33
35     000039     中集集团  0/0/ 34
36     000040     深 鸿 基  0/0/ 35
37     000042     深 长 城  0/0/ 36
38     000043     深南光A  0/0/ 37
39     000045     深纺织A  0/0/ 38
40     000046     泛海建设  0/0/ 39
41     000048     *ST 康达  0/1/ 0
42     000049     德赛电池  0/1/ 1
43     000050     深天马A  0/1/ 2
44     000055     方  大A  0/1/ 3
45     000056     深 国 商  0/1/ 4
46     000058     *ST 赛格  0/1/ 5
47     000059     辽通化工  0/1/ 6
48     000060     中金岭南  0/1/ 7
49     000061     农 产 品  0/1/ 8
50     000062     深圳华强  0/1/ 9
51     000063     中兴通讯  0/1/ 10
52     000065     北方国际  0/1/ 11