awk - Korn shell or Bash. Order the output by the absolute pathname of the shell used.

General support questions
Post Reply
lse123new
Posts: 66
Joined: 2014/05/01 15:48:05

awk - Korn shell or Bash. Order the output by the absolute pathname of the shell used.

Post by lse123new » 2018/05/11 14:31:55

AS SELF STUDY LEARNER I TRIED SOLVE THIS IN AWK CHAPTER OF MY LINUX/UNIX BOOK

12.1 Display from /etc/passwd a list of users and their shells for those using the
Korn shell or Bash. Order the output by the absolute pathname of the shell used.
I came with this ... but sort missing - any help can provided ...? Cent OS 7

awk -F: '($7 ~ /bash/ || $7 ~ /korn/)' /etc/passwd

tunk
Posts: 1206
Joined: 2017/02/22 15:08:17

Re: awk - Korn shell or Bash. Order the output by the absolute pathname of the shell used.

Post by tunk » 2018/05/11 14:50:03

Does this work:
awk -F: '($7 ~ /bash/ || $7 ~ /korn/)' /etc/passwd | sort -t: -k7
BTW: korn is /bin/ksh

lse123new
Posts: 66
Joined: 2014/05/01 15:48:05

Re: awk - Korn shell or Bash. Order the output by the absolute pathname of the shell used.

Post by lse123new » 2018/05/11 15:06:58

[bob@server1 ~]$ awk -F: '($7 ~ /bash/ || $7 ~ /halt/)' /etc/passwd | sort -t: -k7
bob:x:1005:1006::/home/bob:/bin/bash
root:x:0:0:root:/root:/bin/bash
tux:x:1000:1000:tux:/home/tux:/bin/bash
halt:x:7:0:halt:/sbin:/sbin/halt
[bob@server1 ~]$


MUST WORKED THANKS
I did Not have ksh and put halt that had

lse123new
Posts: 66
Joined: 2014/05/01 15:48:05

Re: awk - Korn shell or Bash. Order the output by the absolute pathname of the shell used.

Post by lse123new » 2018/05/11 15:07:58

[bob@server1 ~]$ awk -F: '($7 ~ /bash/ || $7 ~ /halt/)' /etc/passwd | sort -t: -k3
root:x:0:0:root:/root:/bin/bash
tux:x:1000:1000:tux:/home/tux:/bin/bash
bob:x:1005:1006::/home/bob:/bin/bash
halt:x:7:0:halt:/sbin:/sbin/halt
[bob@server1 ~]$

User avatar
TrevorH
Site Admin
Posts: 33221
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: awk - Korn shell or Bash. Order the output by the absolute pathname of the shell used.

Post by TrevorH » 2018/05/11 16:25:13

Though that's not strictly doing what the question asked: "Display from /etc/passwd a list of users and their shells". Yes, the info they ask for is there but you are also displaying the entire line not jsut those 2 requested fields.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

Post Reply