How to display in column format?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    I would like to know how to display my output to this format below:
5000    Bash
300      zsh
0         sh
  1. Relevant commands, code, scripts, algorithms:
echo
echo "METHOD 3: Using only grep command"

echo -n "bash: "
grep "/bin/bash" /etc/passwd | wc -l

echo -n "zsh: "
grep "/bin/zsh" /etc/passwd | wc -l

echo -n "ssh: "
grep "/bin/sh" /etc/passwd | wc -l

Thank you,

  1. The attempts at a solution (include all code and scripts):

  2. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    San Francisco City College. Professor: Aaron Brick

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

man grep and look at the flag -c

If you can follow and understand following code, you should be able to easily adjust it for you needs with only few minor modifications. Hope it helps.

Simple for loop:

for shell in bash ksh tcsh
do
 echo "$shell"
done

Assigning value to variable in the for loop:

for shell in bash ksh tcsh
do
 path=$(which "$shell")
 echo "$shell: $path"
done

Column format, simplified, utilizing tabulator:

for shell in bash ksh tcsh
do
 path=$(which "$shell")
 echo -e "$shell\t$path" # you can exchange $shell and $path anytime
done

Column format, utilizing printf (for perfect alignment)

for shell in bash ksh tcsh
do
 path=$(which "$shell")
# First column format: 5 chars left-aligned
# Second column format: 15 chars right-aligned
 printf '%-5s %15s\n' "$shell" "$path"
done

Thank you..... But I have written the new command lines to get these output below. But I only want to pick out .bash .ksh and .zsh. Is the only command I can use here is grep? How do I use the grep command to get rid of the line that I don't want? So my output will only have 3 lines left.

Thanks in advance,

Jeremy

5189 /bin/bash
2222 /bin/drop
     58 /bin/ksh
      1 /bin/sync
      6 /bin/zsh
      1 /sbin/halt
     33 /sbin/nologin
      1 /sbin/shutdown

output:

5189 /bin/bash
58 /bin/ksh
 6 /bin/zsh

Howsoever you created your output, pipe it through grep -E "bash|ksh|zsh" . If that is not specific enough, try to anchor the patterns, or extend them by meaningful items.