0

This question already has an answer here:

I'd like to check /etc/passwd

    $ cat -n /etc/passwd
         1  ##
         2  # User Database
         3  # 
         4  # Note that this file is consulted directly only when the system is running
         5  # in single-user mode.  At other times this information is provided by
         6  # Open Directory.
         7  #
         8  # See the opendirectoryd(8) man page for additional information about
         9  # Open Directory.
        10  ##
        11  nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false

As we see, the firt 10 lines are commented, the result I desire some command like

    $ cat -n [11:] /etc/passwd
     nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false     
     root:*:0:0:System Administrator:/var/root:/bin/sh
     daemon:*:1:1:System Services:/var/root:/usr/bin/false
     _uucp:*:4:4:Unix to Unix Copy Protocol:/var/spool/uucp:/usr/sbin/uucico

How to accomplish it?

marked as duplicate by jasonwryan, Community Mar 29 '18 at 2:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • sed '/^#/d' </etc/passwd – cuonglm Mar 29 '18 at 2:32
1

If you want to ignore the commented lines, anywhere in the file, without having to count them, then this should do it:

grep -n -v ^# /etc/passwd

The -n option to grep does the same as to cat, number the lines (though the output format is slightly different, grep adds a colon between the line number and the contents and also doesn't pad the numbers.)

The -v option tells grep to print the lines that do not match the regular expression.

And the regular expression ^# matches a literal # only at the beginning of the line.

If what you wanted, instead, was to always skip the first 10 lines, then tail +11 should do it. You can pipe cat -n to it:

cat -n /etc/passwd | tail +11

See the man page of tail for more details, more specifically the option -n (which can be omitted, like here.)

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