Requirement is
I have two files their format is
File1 - input_file
-----
tmp_value|3|number||
tmp_value1|3|alpha||
tmp_value2|6|alpha|AA AA|
tmp_value3|15|number|000000005|
tmp_value4|15|number|000000000000000|
tmp_value5|11|alpha|bbbbbbbbbbb|
tmp_value6|11|alpha|bb bb|
input_file definition
-------------------
column1 = field_name
column2= field_length
column3= datatype
column4=value for the field
File2 - description_file
-----
tmp_value2|1|1|6|alpha|
tmp_value4|2|7|15|number|
tmp_value1|3|22|3|alpha|
tmp_value3|15|25|15|number|
reserved1|5|40|10|alpha|
filler1|6|50|6|number|
tmp_value6|7|56|11|alpha|
description_file definition
----------------------
column1 = field_name
column2= s1.no
column3= offset
column4=field_length
column5=datatype
fillers can be = fillers1 ...filler<n>
reserved can be = reserved1... reserved<n>
Total length of string can be 6+15+3+15+10+6+11 =66
The resulted inputstring needed as per description_file is
|AA AA 000000000000000 000000000000005 000000bb bb |
Description of above result
tmp_value2|1|1|6|alpha| ------------> value is |AA AA | (spaces for remaining 1 character)
tmp_value4|2|7|15|number| ----------> value is |000000000000000| samelength so subsitituted as same
tmp_value1|3|22|3|alpha| ----------> value is | | - it is empty in input_file so subsituted spaces
tmp_value3|15|25|15|number| --------> value is |000000005| - filled remaining zero's leading
reserved1|5|40|10|alpha| ------------> value is | | - it is reserved with alpha as datatype so subsituted spaces
filler1|6|50|6|number| --------------> value is |000000| - it is filler with number as datatype so subsituted zero's
tmp_value6|7|56|11|alpha|-----------> value is |bb bb | - (spaces for remaining 6 character)
Conditions are:
1)I need to loop thru description file each line with each line in input_file.
2)if column1 in both file r equals then i need to take the value of column4 in input_file and have it in a string.
3)For the above there r certain conditions
if column1=column1
then take column4 of input_filevalue
if column4 of input_file value length equals length =column4(field_length) of description_file
result=result+column4(field_value)
if column4(field_value) length is not equal to field_length
if column5(datatype) = number
fill leading zero's to the value to make to that field_length
then
result=result+value
if column5(datatype) = alpha
fill trailing spaces to value to make to that field_length
then
result=result+value
if column1(description_file) not present in input_file
if column5(datatype) = number
then
fill zero's to the value to make to that field_length
result=result+value
if column5(datatype) = alpha
then
fill spaces to value to make to that field_length
result=result+value
if column1(description_file) has string reserved or filler
if column5(datatype) = number
then
fill zero's to the value to make to that field_length
result=result+value
if column5(datatype) = alpha
then
fill spaces to value to make to that field_length
result=result+value
i wrote a shell script for by refering unix.com but still i am not getting proper
result and trailing spaces and forming of string is not correct
---------- Post updated at 01:05 AM ---------- Previous update was at 12:44 AM ----------
i am not much familler in shell script .. so need help on this