- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to display a output by column clearly
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
04-18-2008 05:37 AM
04-18-2008 05:37 AM
cat myfile | awk -F: '{ print $1,$2}'
the output is as below
peter 5424
amy 4324
george 4324
stephanie 6583
but each column only have 1 space only , so it is not good to read, if I want the output show by column more clearly as below ,
peter 5424
amy 4324
george 4324
stephanie 6583
can advise what can i do ? thx
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2008 05:47 AM
04-18-2008 05:47 AM
Re: How to display a output by column clearly
Use 'printf' for formatted printing. Also, eliminate the useless 'cat' process! The arguments to 'awk' specify the input file:
# awk '{printf "%-15s %6d\n",$1,$2}' myfile
peter 5424
amy 4324
george 4324
stephanie 6583
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 01:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 02:32 AM
04-19-2008 02:32 AM
Re: How to display a output by column clearly
Tabs don't work well if you have fields that vary in width from "peter" to "stephanie".
Tabs only work if you have a human adding them or advanced AI technology to do the computations. And then you might as well use JRF's printf fixed width.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 03:08 AM
04-19-2008 03:08 AM
Re: How to display a output by column clearly
awk '{ printf("%-15s\t%10d\n", $1, $2)} ' filename
and with two tabs:
awk '{ printf("%-15s\t\t%10d\n", $1, $2)} ' filename
Rgds,
Rasheed Tamton.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 03:52 AM
04-19-2008 03:52 AM
Re: How to display a output by column clearly
> Rasheed: If that is the case, then this would be the solution.
> awk '{ printf("%-15s\t%10d\n", $1, $2)} ' filename
...and what value does that add? Why would THIS be the solution?
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 04:08 AM
04-19-2008 04:08 AM
Re: How to display a output by column clearly
James (JRF) I agree. I realized it after I posted. I have not checked your first posting correctly. I had looked the output of the command from your posting and did not check your command itself. I did it after I posted it. It is 99.9% same. Mine just gives additional tabs!!!
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 04:41 AM
04-19-2008 04:41 AM
Re: How to display a output by column clearly
> Rasheed.
Thanks. I find that embedded tab characters are more trouble than not. Most generally a 'tab' is considered 8-spaces worth but that is only a default.
Printing lines with tabs embedded between fields can result in mis-aligned output in some printer configurations. To correct this, when tabs have been used, use the 'expand' filter described in the manpages.
If you want extra whitespace in formatted printing, you can always do things like:
# printf "%12s%8s%12s\n" "thank" "" "you"
...that's three (3) fields with the second being the imposition of eight (8) blanks --- a "tab-worth" by default.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 05:12 AM
04-19-2008 05:12 AM
Re: How to display a output by column clearly
So using your method (without using tabs), it would be like this:
awk '{printf "%-15s%10s%6d\n",$1,"" ,$2}' filename
Regards,
Rasheed Tamton.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2008 05:41 AM
04-19-2008 05:41 AM
Re: How to display a output by column clearly
> Rasheed: So using your method (without using tabs), it would be like this:
> awk '{printf "%-15s%10s%6d\n",$1,"",$2}' filename
Yes, that would be the way I would write it to impose ten (10) blanks between the two data fields. I find that this is much easier to read than [which this forum will render less readable, too!]:
# awk '{printf "%-15s %6d\n",$1,$2}' filename
Regards to you Rasheed!
...JRF...