If you use vi, a simple ":set nu" will also provide line numbers. How many other (simple) ways are there to number lines in a file? You'd think UNIX tool designers were BASIC programmers :-). BASIC...

  10 print "hello world"
  20 goto 10

Those were simpler times.

But I digress. Getting back to the topic. Why do we need a "cat -n" and an "nl"? Feature bloat seems to creep into even simple UNIX utilities.

And here are a couple of more goods ways of finding a line number using sed or grep and a pattern:

  sed -n /"easily"/'{=;p;}' < data_analysis.txt
  34
           I could easily implement netblock blocking in using an

  grep -n "easily" data_analysis.txt
  34:        I could easily implement netblock blocking using an

Or use grep to label all the lines with numbers:

  grep -n "^.*$" data_analysis.txt

We're lucky to have so many tools in the toolbox.

When I was learning linux more than 20 years ago Eric Harrison explained it
to me: "Linux is easy because it has very simple tools, each doing only one
thing well. However, there are thousands of little tools."
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to