- 论坛徽章:
- 780
|
本帖最后由 Herowinter 于 2014-07-22 11:58 编辑
没楼上的大神写得好。
回复 1# zsjan - awk -F'|' 'function trim(s){gsub(/^[[:space:]]*|[[:space:]]*$/,"",s);return s} /^%[[:space:]]*$/{++n} !n&&NF==4{s1=trim($2);s2=gensub(/.*"([0-9]+).*/,"\\1",1,$4)} n&&NF==4{$0=sprintf("%8d |%9d |%9d | \042%010d\042",trim($1),s1+trim($2),trim($3),s2+gensub(/.*"([0-9]+).*/,"\\1",1,$4))} n!=1||NF==4' i
- #this is my file
- %start
- 16 | 42 | 1 | "0000000762"
- 16 | 43 | 1 | "0000000763"
- 16 | 44 | 1 | "0000000764"
- 16 | 45 | 1 | "0000000765"
- 16 | 46 | 1 | "0000000766"
- 16 | 47 | 1 | "0000000767"
- 16 | 48 | 1 | "0000000768"
- 1 | 49 | 1 | "0000000769"
- 2 | 49 | 1 | "0000000770"
- 3 | 49 | 1 | "0000000771"
- 4 | 49 | 1 | "0000000772"
- 5 | 49 | 1 | "0000000773"
- 6 | 49 | 1 | "0000000774"
- 7 | 49 | 1 | "0000000775"
- 8 | 49 | 1 | "0000000776"
- %
- I = 20
- cat i
- #this is my file
- %start
- 16 | 42 | 1 | "0000000762"
- 16 | 43 | 1 | "0000000763"
- 16 | 44 | 1 | "0000000764"
- 16 | 45 | 1 | "0000000765"
- 16 | 46 | 1 | "0000000766"
- 16 | 47 | 1 | "0000000767"
- 16 | 48 | 1 | "0000000768"
- %
- I = 31
- #this is my file
- %start
- 1 | 1 | 1 | "0000000001"
- 2 | 1 | 1 | "0000000002"
- 3 | 1 | 1 | "0000000003"
- 4 | 1 | 1 | "0000000004"
- 5 | 1 | 1 | "0000000005"
- 6 | 1 | 1 | "0000000006"
- 7 | 1 | 1 | "0000000007"
- 8 | 1 | 1 | "0000000008"
- %
- I = 20
复制代码 |
|