1

Kind of amused here, I'm trying to pass the prereqs to get into the Udacity Course on High Performance Computer Architecture by Georgia Institute of Technology For the life of me I can't figure out what they want,

Question reads,

To list the contents of a file, with line numbers for non-blank line shown use the command with an option: ________ ___ filename.

I've tried nl. It didn't work. Most bizarre question ever.

Question

  • 3
    Not sure we need an image of the textual question, given that you've reproduced the question in text... – Jeff Schaller Apr 18 '18 at 0:27
5

While cat's numbering is not POSIX, nl is, and POSIX also defines the numbering styles that nl uses:

−b type  Specify which logical page  body  lines  shall  be  numbered.
         Recognized types and their meaning are:

         a       Number all lines.

         t       Number only non-empty lines.

         n       No line numbering.

         pstring Number  only  lines  that  contain  the basic regular
                 expression specified in string.

         The default type for logical page body shall be t (text lines
         numbered).

So, even though it is the default:

nl -bt filename
  • I accepted this answer despite knowing it before I asked the question just because I think it'll be of more use to future visitors =) – Evan Carroll May 28 '18 at 6:56
2

Apparently, cat also has that option,

-b, --number-nonblank number nonempty output lines, overrides -n

So now I guess cat -b and nl are the same. Joys!

$ cat -b ./foo.py 
     1  a = 5
     2  a = a + 1

     3  print "foobarbaz" + str(a);

$ nl ./foo.py 
     1  a = 5
     2  a = a + 1

     3  print "foobarbaz" + str(a);
  • 3
    wtf. this seems so esoteric that I can't imagine why cat would bother implementing such a feature (especially since nl and cat are both part of coreutils). And it makes me think the authors of that question deliberately went looking for something nobody would know. – Patrick Apr 18 '18 at 1:56

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.