- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Text Allignment problem. ? with TAB space.
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
09-08-2005 06:33 AM
09-08-2005 06:33 AM
I am Trying to print like this : username , uid , gid , gecos
With this command. But the allignment is getting disturbed.
Can any one tell , how to allign 2nd field , so that it will maintain in same column.??
$ sort -t: -k 3n,3 passwd | awk -F ":" '{ print $1 ,"\t","\t","\t",$3,"\t","\t",$4,"\t",$5}' | more
-------------------------------------------------------------------------
nobody -2 -24
root 0 3
daemon 1 5
bin 2 2
sys 3 3
adm 4 4
uucp 5 3
lp 9 7
nuucp 11 11
hpdb 27 1 ALLBASE
sna 28 21 SNAplus2 User,,,
www 30 1
sybase 100 101 ,,,
oracle 101 101 Oracle DBA,,,
dbaumgr 102 102 ,,,
dptrans 103 22 File transfer,,,
d_mirror 104 101 data mirror,x7103,,
sshd 107 103 sshd privsep
uua332 108 104 User34,username;Location2;ad2
tpcak 109 104 User35, Username2;Location3;ad3
-----------------------------------------------------------------------------
Thanks ,
Veri.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:37 AM
09-08-2005 06:37 AM
Re: Text Allignment problem. ? with TAB space.
here is the attachment , that will show clear about the problem. (can be opened with wordpad. )
Thanks ,
Veri.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:41 AM
09-08-2005 06:41 AM
Re: Text Allignment problem. ? with TAB space.
If you want the names left justified:
sort -t: -k 3n,3 passwd | awk -F ":" '{ printf("%-20s,%s,%s,%s\n",$1,$3,$4,$5) }'
If you want the names right justified:
sort -t: -k 3n,3 passwd | awk -F ":" '{ printf("%20s,%s,%s,%s\n",$1,$3,$4,$5) }'
You can change the 20 in %20s to the length of your longest user name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:42 AM
09-08-2005 06:42 AM
Re: Text Allignment problem. ? with TAB space.
# sort -t: -k3n,3 passwd | awk -F ":" '{printf "%12s %4d %4d %s\n",$1,$3,$4,$5}'
...adjusting the widths to suit your tastes/needs.
Regards!
...JRF...
Try something like this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:44 AM
09-08-2005 06:44 AM
Re: Text Allignment problem. ? with TAB space.
Use the 'printf'
sort -t: -k 3n,3 passwd | awk -F ":" '{ printf
%-9s %-4s %-4s %-25s\n", $1, $3, $4, $5}' | more
You are defining the length of the fields to print. Example, $1 has 9 characters, $3 has 4 characters, etc...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:44 AM
09-08-2005 06:44 AM
Re: Text Allignment problem. ? with TAB space.
not exactly sure, but
printf "%-20s\t%10s\t%10s\t%s\n", $1,$3,$4,$5 }
should do the job in nice formatting.
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 06:46 AM
09-08-2005 06:46 AM
Re: Text Allignment problem. ? with TAB space.
sort -t: -k 3n,3 passwd | awk -F ":" '{ printf("%20s %7s %7s %s\n",$1,$3,$4,$5) }'
Change the numbers in the %#s statements to whatever value you want.
man awk
and look at the printf section for more info.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:19 AM
09-08-2005 07:19 AM
Re: Text Allignment problem. ? with TAB space.
Patrick, James works fine ,
Ricks one gives error :
$ sort -t: -k 3n,3 passwd | awk -F ":" '{ printf %-9s %-4s %-4s %-25s\n", $1, $3, $4, $5}' | more
syntax error The source line is 1.
The error context is
{ printf >>> % <<< -9s %-4s %-4s %-25s\n", $1, $3, $4, $5}
awk: The statement cannot be correctly parsed.
The source line is 1.
$
--------------------------------------------------------------
And Patrick's last one excellent , Patrick, how to make the names left allinged.
Thanks all,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:31 AM
09-08-2005 07:31 AM
Re: Text Allignment problem. ? with TAB space.
And Thanks all , its working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:32 AM
09-08-2005 07:32 AM
Re: Text Allignment problem. ? with TAB space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:38 AM
09-08-2005 07:38 AM
Re: Text Allignment problem. ? with TAB space.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2005 07:49 AM
09-08-2005 07:49 AM
Re: Text Allignment problem. ? with TAB space.
Now I understood the syntax and details of %s with printf , and worked fine. Thanks for all the help and quick replies.