- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Problems with PRINTF...
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
10-22-2002 04:03 PM
10-22-2002 04:03 PM
I have a text document that has 7 columns. The document is a result of echo'ing a group of variables. The document has up to 100 lines, but when I view the data it is not aligned great. It is all jagged and over the place, making it hard to view. Someone has told me that I can use PRINTF to specify column widths and tab delimeters to clean things up, but after revewing the man pages on PRINTF I am lost. Is there anyone that can help me??
Thanks,
Mike Button
P.S. The columns are like this.
1 -> string
2 - 7 -> numeric (1 -5 max per column)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 04:11 PM
10-22-2002 04:11 PM
SolutionOne way to do it is with awk. With printf, you specify the type of field and the length of the field. For strings, you use the %s parameter. For numbers, you have several choices, but you'll probably want the %d parameter for decimal integers. Something like this might work:
awk '{printf("%20s %6d %6d %6d %6d %6d %6d\n", $1, $2, $3, $4, $5, $6, $7)}' myfile
The \n adds a new line. You can also use \t to insert tab characters, but specifying the field lengths usually makes things print pretty cleanly without any tabs.
I know you can use printf in shell scripts but I haven't played with it. The printf in awk is pretty much like the one in C and Perl, and it gets the job done for me.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 04:21 PM
10-22-2002 04:21 PM
Re: Problems with PRINTF...
Any suggestion, here is my command:
awk '{print ("20s %6d %6d %6d %6d %6d %6d\n", $1, $2, $3, $4, $5, $6, $7)}' myfile >myfile2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 04:22 PM
10-22-2002 04:22 PM
Re: Problems with PRINTF...
You typed 'print' instead of 'printf', and your first parameter should be %20s instead of just 20s. Try it that way and see what you get.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2002 04:24 PM
10-22-2002 04:24 PM
Re: Problems with PRINTF...
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 04:44 PM
10-23-2002 04:44 PM
Re: Problems with PRINTF...
You don't have to do that in awk, you can do the same thing in your C program.
printf("%20s%7d\n", mystring, myint);
will put the string right justified starting at the 20th column and the integer at right justified at the 17th column.