LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   converting File layout from pipe to fixed length based on control file (https://www.linuxquestions.org/questions/linux-newbie-8/converting-file-layout-from-pipe-to-fixed-length-based-on-control-file-4175562221/)

kumar98 12-23-2015 02:52 PM

converting File layout from pipe to fixed length based on control file
 
I have the source file which is pipe demilited and i need the data to be converted into fixed length which is defined in control file.

i am maintaining the control file as i have several source file to be converted to respective fixed length file.The control file specifies the field position for source and target. There can be some default field in target which dont need any transformation form source so, i mentioned as -1 with default value in control file



Source file
AA|TEST1|DATA1
BBB|TEST2|DATA2
CCCC|TEST3|DATA3
DDDDD|TEST4|DATA4

Control file
sourcefield|target field position|default value
3|1:8|
1|9:12|
-1|13:14|X
2|15-20|

Target File ( i provided ~ to specify the empty space and ^ to specify the end of line with 20 byte)
DATA1~~~AA~~X~TEST1~^
DATA2~~~BBB~X~TEST2~^
DATA3~~~CCCCX~TEST3~^
DATA4~~~DDDDX~TEST4~^


Can you provide pointers /script to perfom this kind of file layout conversion

Thanks

TB0ne 12-23-2015 03:16 PM

Quote:

Originally Posted by kumar98 (Post 5468134)
I have the source file which is pipe demilited and i need the data to be converted into fixed length which is defined in control file.

i am maintaining the control file as i have several source file to be converted to respective fixed length file.The control file specifies the field position for source and target. There can be some default field in target which dont need any transformation form source so, i mentioned as -1 with default value in control file

Source file
AA|TEST1|DATA1
BBB|TEST2|DATA2
CCCC|TEST3|DATA3
DDDDD|TEST4|DATA4

Control file
sourcefield|target field position|default value
3|1:8|
1|9:12|
-1|13:14|X
2|15-20|

Target File ( i provided ~ to specify the empty space and ^ to specify the end of line with 20 byte)
DATA1~~~AA~~X~TEST1~^
DATA2~~~BBB~X~TEST2~^
DATA3~~~CCCCX~TEST3~^
DATA4~~~DDDDX~TEST4~^

Can you provide pointers /script to perfom this kind of file layout conversion

Read the LQ Rules and "Question Guidelines" link in my posting signature. We WILL NOT provide you a script, or write things for you. We WILL always be happy to help you....this begins with you post what YOU have written/tried first, and telling us where you're stuck.


All times are GMT -5. The time now is 09:46 PM.