ashikin_8119 0 Newbie Poster

Hi all;

Really need your help on writing the shell script based on the condition below.
I need to re generate file and display message on the status of the file.


I need re-write the file by checking whether the first line starts with '1MBB'.
If the first condition fail then
I need to throw an error message (this part i can do).
Else
(I need to check whether the file contains batch(es) or not. Batch(es) denote by line starts with 'HMBBCREDC'.)

If no line starts with 'HMBBCREDC' then
throw error message - no need to re - generate file
Else
(
There's a line that starts with 'HMBBCREDC' then
check the transactions under that batch :
The lines under that batch need to have at least:
1 line start with '001'
1 line start with '002',
1 line start with '003',
1 line start with '004',
1 line start with '005',
1 line start with '006',
1 line start with '007',
1 line start with '008'
)
If one line doesn't start with any of cases specify above then
throw an error message and reject the whole file
(-that's mean no need to re generate the file)
Else
Re write the file with
File header - 1st line that starts with '1MBB'
Batch 1 - 2nd line that starts with 'HMBBCREDC'
Transaction(under batch 1) - Lines that starts with '001' till '008'
Batch 2 (if any)
Transaction(under batch 2 - if any)
.
.
.

Example

Case 1:
===========

1MBB001200805160000135
HMBBCREDC20080515027001015791				 (i)
001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569
009027001015791200805150000000311864400000004207500000003076569
HMBBCREDT20080515027001015791				  (ii)001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569
HMBBCREDC20080515027001015791				 (iii)001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569

Result:
No need to re generate file since 1 batch (batch iii) fail, the whole file reject

File Hdr - Pass
Batch (i) - Pass
Batch (ii) - Discard the batch since starts with 'HMBBCREDT' instead of 'HMBBCREDC'
Batch (iii) - Fail (doesn't contains transaction that starts with '006') .

Output:

Echo "Incorrect File Format"


Case 2:
===============

1MBB001200805160000135					
HMBBCREDC20080515027001015791				 (i)001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569
HMBBCREDT20080515027001015791				 (ii)001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000042172701200000000005061000000005
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569
HMBBCREDC20080515027001015791				  (iii)001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569

Result:
Need to re generate file ( The file contains file header, batch (i), batch (iii) )

File Header - Pass
Batch (i) - Pass
Batch (ii) - Discard the batch since starts with 'HMBBCREDT' instead of 'HMBBCREDC'
Batch (iii) - Pass

Output:

1MBB001200805160000135		
HMBBCREDC20080515027001015791
001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569
HMBBCREDC20080515027001015791
001027001015791200805151107078954393180009315150420080515269115
001027001015791200805151107078954047880201072650420080515269116
002027001015791200805150000000311864400000000012600000000000000
003027001015791200805150000000133885701380000000018476000000013
004027001015791200805150000000042172701200000000005061000000004
005027001015791200805150000000124546601380000000017187000000012
006027001015791200805150000000011259401380000000001351000000001
007027001015791200805150000000000000002000000000000000000000000
008027001015791200805150000000311864400000004207500000003076569

How can i combine everything in one script? Someone pls help me to solve this problem,thank you in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.