LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-23-2015, 03:52 PM   #1
kumar98
LQ Newbie
 
Registered: Dec 2015
Posts: 1

Rep: Reputation: Disabled
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
 
Old 12-23-2015, 04:16 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,916

Rep: Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689Reputation: 3689
Quote:
Originally Posted by kumar98 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell: copy files based on two strings at fixed locations in file contents tankwart Programming 2 10-09-2014 12:25 PM
[SOLVED] Sorting filenames based on length of the file zama Linux - Software 5 03-26-2012 05:22 AM
bash/sed/awk fill each line in text file with space to fixed length khairil Programming 11 01-09-2008 06:28 AM
problems reading in fixed-length record file naijaguy Programming 1 08-24-2004 03:34 PM
csv to fixed-length file roballen Programming 0 03-11-2004 04:12 AM


All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration