0

I want to print the output of usernames from /etc/passwd into multiple columns. The output from my server is

[root@master vdabas]# cat -n /etc/passwd | cut -f1 -d":"

 1  root
 2  bin
 3  daemon
 4  adm
 5  lp
 6  sync
 7  shutdown
 8  halt
 9  mail
10  operator
11  games
12  ftp
13  nobody
14  systemd-network
15  dbus
16  polkitd
17  sshd
18  postfix
19  vdabas
20  vani
21  delhi

I want the output to be as below:

 1  root            8  halt             15  dbus
 2  bin             9  mail             16  polkitd
 3  daemon          10 operator         17  sshd
 4  adm             11 games            18  postfix
 5  lp              12 ftp              19  vdabas
 6  sync            13 nobody           20  vani
 7  shutdown        14 systemd-network  21  delhi
3

You can use the pr command to format in 3 columns (-3), omitting pagination (-T):

cat -n /etc/passwd | cut -f1 -d":" | pr -T -3

or perhaps

awk -F: '{print NR,$1}' /etc/passwd | pr -T -3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.