日期:2014-05-16  浏览次数:20691 次

unix shell编程(Ksh) 文件内容分离,求教,谢谢
account Detail file: acc_detl
Java code

H20100520RM                                                                   
D10000289      4999005962          +000074388601+000052345912+000000354951488               
D18834804      4999005244          +000000076168+000000076168+000000000000000            
[color=#FF6600]D19479732      8630147526          +000001000110+000001000110+000000000260880            
D35028000      4900005911          +042645985553+042606672253+000000076412526            [/color]D69000008      4904006485          +000013110899+000013110899+000000577693219            
D69000016      4904006501          +000502371438+000502371438+000000525968999            
T7                                                    



account file: accounts
Java code

19479732
35028000



accounts文件里存放的是:要分离的account 
要求:写一个shell脚本,
将在accounts文件里的account信息从acc_detl文件中抽取出来存放到 accRemove文件中
不在accounts文件里面的account信息存放到accNew文件中。
新生成的accRemove文件和accNew文件结构和acc_detl一样,
H 第一行不变,直接从acc_detl中取,
T 是对应文件中的记录条数。

求教,谢谢!







------解决方案--------------------
C/C++ code
$ sed -n '1p' acc_detl > accRemove
$ grep -f accounts acc_detl >> accRemove
$ echo T`grep -f accounts acc_detl |wc -l` >> accRemove
$ cat accRemove 
H20100520RM                                                                   
D19479732      8630147526          +000001000110+000001000110+000000000260880            
D35028000      4900005911          +042645985553+042606672253+000000076412526
T2

------解决方案--------------------
C/C++ code
$ sed -n '1p' acc_detl > accNew
$ sed '1d;$d' acc_detl |grep -v -f accounts >> accNew 
$ echo T`sed '1d;$d' acc_detl |grep -v -f accounts |wc -l` >> accNew 
$ cat accNew 
H20100520RM                                                                   
D10000289      4999005962          +000074388601+000052345912+000000354951488               
D18834804      4999005244          +000000076168+000000076168+000000000000000            
D69000008      4904006485          +000013110899+000013110899+000000577693219            
D69000016      4904006501          +000502371438+000502371438+000000525968999            
T4