How to display in column format?

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions How to display in column format?
# 1  
Old 10-28-2014
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:

Code:
5000    Bash
300      zsh
0         sh



2. Relevant commands, code, scripts, algorithms:

Code:
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,

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



4. 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).

Last edited by Don Cragun; 10-28-2014 at 11:08 PM.. Reason: Add CODE tags.
# 2  
Old 10-28-2014
man grep and look at the flag -c
# 3  
Old 10-29-2014
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:
Code:
for shell in bash ksh tcsh
do
 echo "$shell"
done



Assigning value to variable in the for loop:

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



Column format, simplified, utilizing tabulator:
Code:
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)
Code:
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

# 4  
Old 10-29-2014
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


Code:
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:
Code:
5189 /bin/bash
58 /bin/ksh
 6 /bin/zsh

Moderator's Comments:
Mod Comment When you don't use CODE tags, volunteers reading your posts can't distinguish between a single space and multiple adjacent spaces and/or tabs. Please use CODE tags so we can better help you.

Last edited by Don Cragun; 10-29-2014 at 03:12 PM.. Reason: Add CODE tags.
# 5  
Old 10-29-2014
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to compare 3rd column value with first column and display

Hello Team, My source data (INput) is like below EPIC1 router EPIC2 Targetdefinition Exp1 Expres rtr1 Router SQL SrcQual Exp1 Expres rtr1 Router EPIC1 Targetdefinition My output like SQL SrcQual Exp1 Expres Exp1 Expres rtr1 Router rtr1 Router EPIC1 Targetdefinition... (5 Replies)
Discussion started by: sekhar.lsb
5 Replies

2. Post Here to Contact Site Administrators and Moderators

Display time in 12 hr format

Write a script named time that displays the time in standard 12-hour format, rather than 24-hour format. Allow the user to give a -m option to get 24-hour format. For example: > date Sun Feb 10 10:56:50 CST 2008 > time 10:56 AM > date Sun Feb 10 21:57:07 CST 2008 > time 9:57 PM >... (0 Replies)
Discussion started by: satish24
0 Replies

3. UNIX for Beginners Questions & Answers

Hour display format

Hello Sir/Madam, I'm using Putty utility to run a shell script. I found HOUR display in two positions in UNIX. Is it possible to display in four positions? File name example: my file name is: HourlyData_20160708_1400.txt I'm in the process of comparing current date and time with the file... (15 Replies)
Discussion started by: V1l1h1
15 Replies

4. Shell Programming and Scripting

Hange display format

I have a file , the file content will be modified regularly , its structure as below, the lines are begins with "A" and "B" . #vi file1 this is testing file A aaaaa B bbbbb A ccccc B ddddd A eeeee B fffff A ggggg B hhhhh I would like to have a script to use the... (3 Replies)
Discussion started by: ust3
3 Replies

5. Shell Programming and Scripting

Changing display format

Hi, My file cat a.txt Sat Nov 27 00:02:00 2010 00:02:00 Usr 27: Login by edi on batch. (452) 00:02:09 Usr 27: Logout by on batch. (453) 00:02:09 Usr 27: Login by edi on batch. (452) 00:02:22 Usr 27: Logout by on batch. (453) 00:02:22 Usr 27: Login by edi on batch.... (3 Replies)
Discussion started by: ganeshanbu
3 Replies

6. UNIX for Dummies Questions & Answers

Date format Display Help

I have tried various arguments to get the date display as "Mar 10". I have tried date +"%c" -------> Wed Mar 10 11:51:21 EST 2010 date +"%b%d%Y_%H%M%S" --------> Mar102010_115121 date +"%b%d" -------> Mar10 date +"%t%b%e" ... (3 Replies)
Discussion started by: moveaix
3 Replies

7. UNIX for Advanced & Expert Users

Need to display complete format of ps

Hi All, For one of my script I need to get the complete format of PS as result. Actually in our application, we have to execute some program to get the data for batch files. Now there is some java script is running on unix for this which is not identifiable. I want to know how to... (2 Replies)
Discussion started by: nishank.jain
2 Replies

8. UNIX for Dummies Questions & Answers

Date Display Format

Hello People, How can I display the date in a continuous format along with the time as below : 20091001_154547 i.e yyyymmdd_hhmmss format. Thanks. (3 Replies)
Discussion started by: sushant172
3 Replies

9. UNIX for Advanced & Expert Users

ls -l timestamp display format

The time stamp format using "ls -l" is either mmm dd hh:mm or mmm dd yyyy. For later case, how can I know the hh:mm as well. Thanks. (3 Replies)
Discussion started by: pok.fung
3 Replies

10. Shell Programming and Scripting

ls command format display

Hi I have 3 files $ ls -l -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 SANITY_TEST -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 -rw-r--r-- 1 osbadmin osbadmin 427701 Apr 22 12:06 Success 123333 (1) I need to see this "SANITY_TEST" "Success 123333" "Success... (6 Replies)
Discussion started by: mnmonu
6 Replies
Login or Register to Ask a Question