LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-26-2017, 12:06 PM   #1
JUSTIN3499
LQ Newbie
 
Registered: Sep 2017
Posts: 2

Rep: Reputation: Disabled
Post Linux help: using a command to list certain categories in a directory with the number of employees


So for instance refer to this data.

004,Hendrix,James,Engineering,9
237,Cauthon,Mat,Marketing,2
889,Wallace,Mia,Accounting,8
096,Uffhark,Joan,Administration,9
120,Carrington,Blake,Accounting,8
053,Draper,Don,Marketing,3
413,Zappa,Francesco,Engineering,9
285,Gunvalson,Victoria,Engineering,9
744,Watts,Charles,Administration,8
409,Wilson,Brian,Engineering,9
346,McCormick,Kenneth,Marketing,2
070,Berlin,Rachel,Marketing,2
555,Zombie,Robert,Administration,7
217,Burns,Fahr,Accounting,8
154,Tennille,Antoinette,Engineering,9
843,Trakand,Elayne,Administration,8
654,Grumby,Jonas,Administration,7
026,Corleone,Michael,Marketing,3
599,March,Christopher,Engineering,9
808,Mann,Yoda,Engineering,9

Now how would i make a list of data showing only the department and the total number of employees it has. For instance how would I would a Linux command to show the Engineering department and how many people work in that department based off the data? What i am concluding is using the "awk" command but im not for sure. someone please help.
 
Old 09-26-2017, 12:24 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 22,329

Rep: Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026Reputation: 6026
Quote:
Originally Posted by JUSTIN3499 View Post
So for instance refer to this data.

004,Hendrix,James,Engineering,9
237,Cauthon,Mat,Marketing,2
889,Wallace,Mia,Accounting,8
096,Uffhark,Joan,Administration,9
120,Carrington,Blake,Accounting,8
053,Draper,Don,Marketing,3
413,Zappa,Francesco,Engineering,9
285,Gunvalson,Victoria,Engineering,9
744,Watts,Charles,Administration,8
409,Wilson,Brian,Engineering,9
346,McCormick,Kenneth,Marketing,2
070,Berlin,Rachel,Marketing,2
555,Zombie,Robert,Administration,7
217,Burns,Fahr,Accounting,8
154,Tennille,Antoinette,Engineering,9
843,Trakand,Elayne,Administration,8
654,Grumby,Jonas,Administration,7
026,Corleone,Michael,Marketing,3
599,March,Christopher,Engineering,9
808,Mann,Yoda,Engineering,9

Now how would i make a list of data showing only the department and the total number of employees it has. For instance how would I would a Linux command to show the Engineering department and how many people work in that department based off the data? What i am concluding is using the "awk" command but im not for sure. someone please help.
What have you done/tried so far?? And read the "Question Guidelines" and LQ Rules, please...we're happy to help you, but posting a homework question without showing your own efforts isn't going to get you much.

Awk is complex and can do quite a bit. You can also accomplish this with a bash script, using grep and other things as well. Perl, python, and any other scripting/programming language can also be used. You also don't tell us what your data above actually is, or where it comes from.
 
Old 09-26-2017, 12:32 PM   #3
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 11,017

Rep: Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250Reputation: 1250
Why not grep for the various departments?
 
Old 09-26-2017, 12:39 PM   #4
JUSTIN3499
LQ Newbie
 
Registered: Sep 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
I have tried awk to cut out specific fields in the directory and list only the fields I wants for instance awk -F "," '{print $4}' labdata | grep Engineering | wc -l. But when i do that it only list the number of times it shows up for instance "7" is what pops up I dont know how to get the word Engineering into the command line with it.
 
Old 09-26-2017, 01:17 PM   #5
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 1,293

Rep: Reputation: 595Reputation: 595Reputation: 595Reputation: 595Reputation: 595Reputation: 595
You can count each department in an string-addressed array (hash).
At the END print each department with its count.
Code:
awk -F "," '{cnt[$4]++} END { for (i in cnt) print i,cnt[i] }' labdata
The for loop lets i cycle through each (string-)index of cnt[]
 
Old 09-26-2017, 06:56 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,493

Rep: Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099
That counts the number of instances of each department in the list, not the total employes, but is certainly an excellent starting point for the OP to resolve the issue.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using spawn command to find the number of files in a directory. jithuchandran Linux - Newbie 5 12-08-2014 12:54 PM
Getting a directory list with a line specifying the number of filenames displayed. stf92 Slackware 12 06-01-2013 04:25 AM
shell script to seperate male employees from female employees sarahm Linux - Newbie 11 05-11-2012 04:36 PM
ls command and displaying the number of files in your current directory? revsarah Linux - General 5 10-15-2010 07:40 PM
Command to list total number of files. WillieB_72 Linux - General 3 01-29-2003 10:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration