•
•
•
•
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 425,896 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 1,937 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: Programming Forums
Views: 1052 | Replies: 0
![]() |
•
•
Join Date: Nov 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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:
===========
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:
===============
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:
How can i combine everything in one script? Someone pls help me to solve this problem,thank you in advance.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Shell script Help (Shell Scripting)
- shell script prob (Shell Scripting)
- Shell Script for Load monitoring! (Shell Scripting)
- help with my fist script (Shell Scripting)
- Linux Shell Script needs help writing program (Shell Scripting)
- web page statistics - my first bash script (Shell Scripting)
- Shell script for identifying FS TYPE and mounting via LOOP device (Shell Scripting)
- Why my shell script doesn't delete a file ?? (Shell Scripting)
- Bash shell screipt help (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: print one liners
- Next Thread: Shell Script


Linear Mode