Dear guys, I've just to tried your solution but i guessed it didnt match my need. Let me explain my problem clearly
I have a source file with a total of 15 lines(line 4,5,6,11,12,13 are empty lines)as below:
Source file
Code:
1: HHR _PCBCheck, ,
2: COMMENT Name ....... : PCBCheck
3: COMMENT Version . .. : V468A
4:
5:
6:
7: -- Used for initialize()
8:
9: COMMENT This variable shall be used to access Class level functions and method.
10: -------------------------------------------------------------------------------
11:
12:
13:
14: ELEMENT
15: END FILE
I am looking to find a shell script to convert the source file to a destination file such as:
Destination file
Code:
1: HHR _PCBCheckImpl, ,
2: COMMENT Name ....... : PCBCheck
3: COMMENT Version . .. : V468A
4:
5: CPara *ROL_CParaImpl;
6:
7: -- Used for initialize()
8:
9: COMMENT This variable shall be used to access Class level functions and method.
10: -------------------------------------------------------------------------------
11: COMMENT [REG-AS54] :
12: COMMENT When a class instance inherits a specific interface, it shall implement a method named "get<Name>Instance".
13: COMMENT This method shall return a pointer to the <InterfaceName> instance
14: ELEMENT
15: END FILE
The destination file should have a same line number with source file(15 lines).
I also define a condition file to easy for finding and replacement.
Condition file:
Code:
[FIND 1]
HHR _PCBCheck, ,
[REPLACE 1]
HHR _PCBCheckImpl, ,
[FIND 2]
-- Used for initialize()
[REPLACE 2]
CPara *ROL_CParaImpl;
-- Used for initialize()
[FIND 3]
ELEMENT
[REPLACE 3]
COMMENT [REG-AS54] :
COMMENT When a class instance inherits a specific interface, it shall implement a method named "get<Name>Instance".
COMMENT This method shall return a pointer to the <InterfaceName> instance
ELEMENT
I suppose a shell script will do as below flow chart:
step0: i=1
step1: read block text A (including empty line) from section [FIND i] in Condition file
step2: find A from Souce file
step3: if found, replace the text A with text in section [REPALCE i] (including empty line) in Condition file then output to Destination file
step4: i=i+1
step4: back step1 while i<=n
I am really want a shell script (bash or sh shell) like that and hope you take your valuable time to help me.
Thanks and thanks again.