0

Ok I've done:

cat /etc/passwd | awk -F: '{ print $1 }'
  • -F ==> Specify a file seperator for delineating data fields in a line
  • $1 ==> Represents the first field in the input

but how to only print users with id over 1000?

  • @JeffSchallerIf a question deserves a answer, I would also think it deserves atleast one up vote, this is so stupid – somethingSomething Sep 4 '18 at 18:34
3

As steeldriver pointed out in a comment, you could simply add a condition to the print statement so that it only prints when the condition is true:

awk -F: '$3 > 1000 { print $1 }' /etc/passwd

Here, the $3 > 1000 is the condition. Awk can also read files directly, so you can avoid a cat and a pipe | by providing the filename directly to awk, either directly as above, or with a redirection:

awk -F: '$3 > 1000 { print $1 }' < /etc/passwd

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.