HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Data formating
Operating System - HP-UX
1833704
Members
2535
Online
110062
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
Go to solution
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
02-16-2004 10:45 AM
02-16-2004 10:45 AM
Hello:
I was put to the task of formating data blocks from our legacy system to a flat ascii format. I have created a simple script that worked great until the programmers started sending huge data records beyond the old system maximun of 756 characters. We have agreed to insert an undescore (_) on position 756 indicating that the next line were to be continuation of the same record. So, I came to the idea of searching data until it finds an undescore and a line feed (_\012) and delete the pair, hence concatenating the next line. This was not as simple as I had planned. See model script bellow:
...
# Split data stream into 756 chunks and delete trailing spaces
fold -b -w756 $1 | sed 's/;[ ]*/;/g' > $1.foo
# replace '_' with 'u' and '\012' with 'l'
sed 's/_/u/g' $1.foo | tr '\012' 'l' > $1.mid
# add an end of record for sed to see bottom of file
echo '' >> $1.mid
# Delete 'ul' (concactenate), add linefeed and replace the _ were they should be
sed 's/ul//g' $1.mid | tr 'l' '\012' | tr 'u' '_' > $1.dat
...
The problem with this is that Iam IOing like a madd man. The script is building 3 times as many files to make one usable output file. Also, input data may have l's and u's in it, causing unexpected results.
This is a question for all of you sed, awk and perl masters.
Is there a way get a flat ASCII file using the least middle steps? May be a oneliner (or two)?
Appreciate any ideas. Included is a tiny sample input file.
I was put to the task of formating data blocks from our legacy system to a flat ascii format. I have created a simple script that worked great until the programmers started sending huge data records beyond the old system maximun of 756 characters. We have agreed to insert an undescore (_) on position 756 indicating that the next line were to be continuation of the same record. So, I came to the idea of searching data until it finds an undescore and a line feed (_\012) and delete the pair, hence concatenating the next line. This was not as simple as I had planned. See model script bellow:
...
# Split data stream into 756 chunks and delete trailing spaces
fold -b -w756 $1 | sed 's/;[ ]*/;/g' > $1.foo
# replace '_' with 'u' and '\012' with 'l'
sed 's/_/u/g' $1.foo | tr '\012' 'l' > $1.mid
# add an end of record for sed to see bottom of file
echo '' >> $1.mid
# Delete 'ul' (concactenate), add linefeed and replace the _ were they should be
sed 's/ul//g' $1.mid | tr 'l' '\012' | tr 'u' '_' > $1.dat
...
The problem with this is that Iam IOing like a madd man. The script is building 3 times as many files to make one usable output file. Also, input data may have l's and u's in it, causing unexpected results.
This is a question for all of you sed, awk and perl masters.
Is there a way get a flat ASCII file using the least middle steps? May be a oneliner (or two)?
Appreciate any ideas. Included is a tiny sample input file.
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2004 11:41 AM
02-16-2004 11:41 AM
Re: Data formating
maybe this will work for you
fold -b -w756 $1 |
while read line
do
#everything but last char
x=${line%?}
lastChar=${line#$x}
if [[ $lastChar = "_" ]] ;then
#print line without the ending underscore
#and without a newline
print -nr $x
else
print -r $line
done > $1.dat
fold -b -w756 $1 |
while read line
do
#everything but last char
x=${line%?}
lastChar=${line#$x}
if [[ $lastChar = "_" ]] ;then
#print line without the ending underscore
#and without a newline
print -nr $x
else
print -r $line
done > $1.dat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2004 11:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2004 01:48 AM
02-18-2004 01:48 AM
Re: Data formating
Thank you Curt, both solutions are a winner. My personal preference is for awk but as the great master said: "There is more than one way to skin a cat"
Thanks again.
Victor
Thanks again.
Victor
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
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP