up vote 3 down vote favorite
share [g+] share [fb]

How do I go about doing this:

Using the sort, grep and less commands (connected with a pipe), sort the /etc/passwd file in alphabetical order and display only the lines ending in the word "false".

link|improve this question

Is this homework? – innaM Nov 30 '09 at 10:01
1  
Apparently so. HardwareMuch even tagged it that way. – Doug Harris Nov 30 '09 at 18:45
Yes it is, Manni, hence the 'homework' tag :) – Phoshi Nov 30 '09 at 18:45
Indeed! well, duh! – innaM Dec 4 '09 at 21:41
feedback

2 Answers

up vote 4 down vote accepted
grep false$ /etc/passwd | sort | less
link|improve this answer
+1, It would be a little more correct to use sort -t:. But this works on /etc/passwd. – nik Nov 30 '09 at 5:03
Hm, yeah, I guess you don't need the ^.* ... – Lawrence Velázquez Nov 30 '09 at 5:04
8  
For better performance, you should do grep first, then sort. – Kim Nov 30 '09 at 5:11
You didn't use less here. – innaM Nov 30 '09 at 10:01
all comments taken into consideration, answer updated. – John T Nov 30 '09 at 18:25
feedback

I just tried this on Mac OS X 10.6, but I feel that it should work on Linux also:

sort /etc/passwd | grep '^.*false$' | less
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.