HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: How to reformat a fixed length file using scri...
Operating System - Linux
1828038
Members
2124
Online
109973
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2006 02:26 PM
06-19-2006 02:26 PM
How to reformat a fixed length file using scripting?
Dear all,
I face difficulties to code a script to do a file processing. I was given a file with fixed length records.
My task now is to grep the line record that has the first character with the number 5 and need to substring the line starting from position 12 with a string length of 6 (12,6) to indicate the transaction date.
Then the transaction date will be used to append at the end of the subsequent line of records that has the first character with number 6.
The script has to detect for the change of transaction date in between the records. If there is another line starts with number 5 appear, then the same process has to be done to substring starts from position 12 and length 6.
Then use the new transaction date to append to end of the line of the subsequent records that start with number 6.
The new record format has to be output into a new file.
I have attached a sample file for your understanding of how the file format look like.
Is there a way where awk programming or normal shell script can accomplish this task?
I hope the Unix gurus here can advise me. I will appreciate any help on this matter.
Thank you.
Regards,
Mel
I face difficulties to code a script to do a file processing. I was given a file with fixed length records.
My task now is to grep the line record that has the first character with the number 5 and need to substring the line starting from position 12 with a string length of 6 (12,6) to indicate the transaction date.
Then the transaction date will be used to append at the end of the subsequent line of records that has the first character with number 6.
The script has to detect for the change of transaction date in between the records. If there is another line starts with number 5 appear, then the same process has to be done to substring starts from position 12 and length 6.
Then use the new transaction date to append to end of the line of the subsequent records that start with number 6.
The new record format has to be output into a new file.
I have attached a sample file for your understanding of how the file format look like.
Is there a way where awk programming or normal shell script can accomplish this task?
I hope the Unix gurus here can advise me. I will appreciate any help on this matter.
Thank you.
Regards,
Mel
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2006 03:06 PM
06-19-2006 03:06 PM
Re: How to reformat a fixed length file using scripting?
It's a bit difficult to tell from your file because I don't know if the records are actual text records terminated with a LF, CR, or a CR/LF pair or if they are indeed simply fixed-length records as you seem to imply. I don't know if your attachment is an accurate translation of the data or if you have passed it thru a filter or selected a particular output format. It would be helpful if you indicated if this is actual raw data and what is the record length.
If the records are truly-fixed length w/o a normal record terminator then tools like grep, sed, or awk aren't going to very useful. Your best bet will be Perl because it can easily process fixed-length records as well as normal line-oriented text. Another option is to use dd to unblock the input records and attach a LF to each of these so that the more conventional tools (awk, grep, sed) can then be used.
If the records are truly-fixed length w/o a normal record terminator then tools like grep, sed, or awk aren't going to very useful. Your best bet will be Perl because it can easily process fixed-length records as well as normal line-oriented text. Another option is to use dd to unblock the input records and attach a LF to each of these so that the more conventional tools (awk, grep, sed) can then be used.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2006 10:34 AM
06-20-2006 10:34 AM
Re: How to reformat a fixed length file using scripting?
If the file really is divided into lines like your attachment then you could use this-
awk '/^5/{date=substr($0,12,6)}/^6/{sub("$",date)}//{print}' input > output
Each time it sees a line with a leading 5 it remembers that as date. Each time it sees a line with a leading 6 it appends the current value of date.
awk '/^5/{date=substr($0,12,6)}/^6/{sub("$",date)}//{print}' input > output
Each time it sees a line with a leading 5 it remembers that as date. Each time it sees a line with a leading 6 it appends the current value of date.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2006 11:15 PM
06-20-2006 11:15 PM
Re: How to reformat a fixed length file using scripting?
I have tried to code using perl. It worked!
Thanks to Clay and Mike for your replies.
Thanks to Clay and Mike for your replies.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP