Filtering / etc / passwd on Unix

I would like to filter the content /etc/passwd

, only showing rows for which the value in the third column is greater than 999

.

Is there an easy way to do this with a single liner? I would like to do this without writing boring things for-loop

.

+3


source to share


1 answer


This is an easy way to do it:

awk -F: '$3 > 999' /etc/passwd

      



In this case it is used awk

with a field separator :

and instructs it to print a line if the third field is greater than 999. If you only want to print the first field (username), or plot multiple new lines based on fields, this is the starting point:

awk -F: '{if ($3 > 999) print "user", $1, "uid", $3}' /etc/passwd

      

+8


source







All Articles