Grep and Sort

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Grep and Sort
# 1  
Old 03-30-2013
Grep and Sort

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:

1. Print the number of people that are in the /etc/passwd file with the name of George

2. Sort by name and print the "who" list using pipes to link the commands.

2. Relevant commands, code, scripts, algorithms:

grep, sort

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

1.
Code:
grep -cw "George" /etc/passwd

2. Any advice for this? I am not sure what to do, except use something like
Code:
sort -n who

, but that does not work.

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Brookdale Community College - Lincroft, New Jersey - United States - Dr. Rick Bournique- COMP 145


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).
# 2  
Old 03-30-2013
A) For #2, the problem statement wants you to use a "pipe".
Can you explain what a pipe is, and give some examples?

B) Also, #2 mentions "who". What is "who"? Is it a file? Or what?

If you can understand A) and B), I think you can finish the assignment.
# 3  
Old 03-30-2013
Sir, those are the assignment directions. I will have to email my teacher I guess. The directions are shit.
# 4  
Old 03-30-2013
The assignment directions are not "shit". Smilie The directions are actually very good.

But you cannot finish the assignment unless you understand what a "pipe" is, and what "who" is. You can easily figure that out on your own, with a little research and experimentation.

Did your course mention "pipe" before? If not, you could look for pipe on wikipedia, as used in the computer sense. And think about what "who" might be? Is there a file on your computer called "who"? If not, then what's the other possibility about "who"? Again, you could even find the answer on wikipedia.

Keep at it. I would not email your teacher yet.
# 5  
Old 03-30-2013
Oh, sorry, it sounded like you were asking me what those things were because you didn't know (which you obviously do, so my apologies). I know that "Who" is a command that lists the users currently on the server and piping uses | to create a sequence of commands.

So for #2, maybe something like:

Code:
sort -n | who

# 6  
Old 03-30-2013
It's understandable. No problem.

You understand the terms perfectly. The proposed solution is in the right direction (you're getting warm), but kind of looks like a shot in the dark. Think about it. What exactly do you want to sort?

Do you have access to a computer to test the solution? If so, what happens when you try the proposed solution? Or do you have to do this just on paper?
# 7  
Old 03-30-2013
Oh,
Code:
-n

is for numeric values. So would it just be
Code:
sort | who

And yes I can use Putty to connect to the school server, but only myself and the server admin are usually on, so not sure if it is really working to be honest (his name just might pop up first by default).

EDIT: I tried this and it did not work, because I did a reverse order sort using
Code:
who | sort -r

and my name came first, so that works. So my answer would thus be
Code:
who | sort

. I am not really sure why this order of who and sort works. Is it because you need to run who first so the sort takes the input from the other command (who)?

P.S. I am doing a small grading program for this same lab as well. I will post my results later tonight. Didn't post here because I had not yet tried anything. Should I open a new thread or post here?

Last edited by Jagst3r21; 03-30-2013 at 09:45 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep -v -f and sort|diff which way is faster

Hi Gurus, I have two big files. I need to compare the different. currently, I am using sort file1 > file1_temp; sort file2 > file2_tmp diff file1_tmp file2_tmp I can use command grep -v -f file1 file2 just wondering which way is fast to compare two big files. Thanks... (4 Replies)
Discussion started by: ken6503
4 Replies

2. Homework & Coursework Questions

awk with Grep and Sort

1. The problem statement, all variables and given/known data: Please bare in mind I am a complete novice to this and have very very basic knowledge so please keep any answers as simple as possible and explain in terms I will understand ahha :):) I have a text file of names and test scores... (1 Reply)
Discussion started by: jamesb18
1 Replies

3. Homework & Coursework Questions

awk questions using sort and grep

1. The problem statement, all variables and given/known data: So i'll probably get told off for this but I have a few problems and rather than clog up the whole forum I'll post them here. Please bare in mind I am a complete novice when it comes to all this and so if you help please treat me like a... (4 Replies)
Discussion started by: jamesb18
4 Replies

4. Shell Programming and Scripting

How to sort grep result based on timestamp?

Hi, Trying to sort grep result based on timestamp of the filename. I have the following result and want to sort them on timestampgrep -i 'ERROR' *log*2013* s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:TRANSF_1_1_1> DBG_21216 Finished transformations for Source Qualifier . Total errors ... (5 Replies)
Discussion started by: bobbygsk
5 Replies

5. Shell Programming and Scripting

grep from 3 lines and sort

Pseudo name=hdiskpower54 Symmetrix ID=000190101757 Logical device ID=0601 state=alive; policy=SymmOpt; priority=0; queued-IOs=0 ============================================================================== ---------------- Host --------------- - Stor - -- I/O Path - -- Stats --- ### HW... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

6. Programming

[ask]SQL command act like sort and grep

for example, I have a text file in random content inside, maybe something like this. 234234 54654 123134 467456 24234234 7867867 23424 568567if I run this command cat "filename.txt" | sort -n | grep "^467456$" -A 1 -B 1the result is 234234 467456 568567is it possible to do this command... (2 Replies)
Discussion started by: 14th
2 Replies

7. Shell Programming and Scripting

Grep empty space and sort

Hi Expert, Kindly request for your expertise in this matter. I have below output: 12.125.124.173,xx1.common.com 12.125.124.174,xx2.common.com 12.125.124.175,xx3.common.com 12.125.124.176, 12.125.124.177, 12.125.124.178, 12.125.124.179,xx4.common.com 12.125.124.180,xx5.common.com... (8 Replies)
Discussion started by: regmaster
8 Replies

8. Shell Programming and Scripting

history awk grep sort

can someone help me in the awk part...little confuse on that part. The problem is this: what input each utility gets and what it does with data and what output is provides to the next utility) history | awk '{a++}END{for(i in a){print a " " i}}' | sort -rn | grep '^' Thanks (4 Replies)
Discussion started by: Learnerabc
4 Replies

9. Shell Programming and Scripting

how to grep sort userids

hello folks i have a file that have data like /test/aa/123 /test/aa/xyz /test/bb/xyz /test/bb/123 in above lines i just wants to grep "aa" and "bb". Thanks, Bash (4 Replies)
Discussion started by: learnbash
4 Replies

10. UNIX for Dummies Questions & Answers

Sort/Grep Question

Hello all, I have a test file that has the format: ..... O 3.694950 -.895050 1.480000 O 5.485050 .895050 1.480000 Ti -4.590000 4.590000 2.960000 Ti -2.295000 ... (5 Replies)
Discussion started by: aarondesk
5 Replies
Login or Register to Ask a Question