- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Formating output to fixed lenght
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
05-10-2002 08:05 AM
05-10-2002 08:05 AM
I???m trying for the last few days to get a formatted output on a file.
I have 100???s of windows *82.txt files with this format:
"header*GSIFDS*OO*T"
"H","15650010","1","5/8/2002","5/13/2002","somemore123","B24","B0"
"I","050526","5","16.54","NONE"
"I","050535","6","26.8","NONE"
"I","000936","7","29.92","NONE"
"I","014160","8","47","NONE"
"I","KI21340","9","17.18","NONE"
"I","04460","10","38.7","NONE"
"C","NONE"
"C","NONE"
"C","NONE"
"trailer*GSIFDS*OO*B24*12"
These are comma separated fields on a database, the DBM reads these lines sequentially (quotes and all) and imports them into its own proprietary format.
My task in the UX world is to strip all \r and \n to make it a one liner file ??? which I was able to do with:
tr -d "[\015\012]" < test > testout
My problem is to format each line with a total length of 378 bytes disregarding the length of actual data characters.
My latest script looks like:
rm -f test
cat *82.txt | while read LIN
do
DAT=`printf "%.378s\n" $LIN`
echo $DAT >> test
done
tr -d "[\015\012]" < test > testout
exit
But this is giving me identical *82.txt and test files (no trailing white spaces)
I???ve seen hundreds of posting on getting rid of white spaces but nothing on injecting trailing chr(20).
I???ll appreciate any cmments. Thanks, Victor
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:16 AM
05-10-2002 08:16 AM
Re: Formating output to fixed lenght
I don't know how to check for fixed length string.
But here is inserting blanck space
#insert 5 blank spaces at beginning of each line (make page offset)
sed 's/^/ /'
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:19 AM
05-10-2002 08:19 AM
Re: Formating output to fixed lenght
While I would probably do this in perl of awk (it would be much faster), you can do it within the shell:
Your:
DAT=`printf "%.378s\n" $LIN`
echo $DAT >> test
becomes:
DAT=$(printf '%-378.378s' "${LIN}")
echo "${DAT}" >> test
Note that echo does an implicit linefeed so that no LF is needed in the printf. The quotes around ${DAT} are required to include the white space. I have also replaced your backticks with the more modern syntax $(command)
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:19 AM
05-10-2002 08:19 AM
Re: Formating output to fixed lenght
rm -f test
cat *82.txt | while read LIN
do
printf "%378.378s\n" $LIN >> test
done
tr -d "[\015\012]" < test > testout
exit
HTH
Duncan
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:25 AM
05-10-2002 08:25 AM
Re: Formating output to fixed lenght
First sed the file to append a load of spaces to the end of each line, to guarantee more than 378 chars, then use your printf routine to chop everything back to 378 chars afterwards.
$ is EOL in sed. If you replace it with spaces it just adds the spaces before the EOL.
sed 's/$/ loads of spaces on the end/' infile > outfile
...printf "%.378s\n" $LIN` etc as you did before.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:29 AM
05-10-2002 08:29 AM
Re: Formating output to fixed lenght
here is a script of mine which formats the output of bdf while changing the values to MB's. The principle for formatting can be applied to your file.
cheers
John.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:30 AM
05-10-2002 08:30 AM
Re: Formating output to fixed lenght
rm testout
...
do
printf "%-378s" ${LIN} >> testout
done
exit
No need for command substitution - printf direct to the file.
No need to remove the linefeed because printf hasn't written one.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2002 08:31 AM
05-10-2002 08:31 AM
Re: Formating output to fixed lenght
Your solution works, great answer BTW!!!
Victor