User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 397,839 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,578 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 867 | Replies: 0
Reply
Join Date: Nov 2007
Posts: 7
Reputation: ashikin_8119 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ashikin_8119 ashikin_8119 is offline Offline
Newbie Poster

Re-write file using shell script

  #1  
Jun 20th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Shell Scripting Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 7:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC