4

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".

  • 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
6
grep false$ /etc/passwd | sort | less
  • +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
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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