How Do I Add Line Numbers to a File in Linux?
Contents

How do I add line numbers to a text file?

Using cat to Add Line Numbers to a Text File

Simply replace “file” with the file name you want to add line numbers to, and change “file_name” to the exported name.

How do I show the number of lines in a file in Linux?

How to Count lines in a file in UNIX/Linux

  1. The “wc -l” command when run on this file, outputs the line count along with the filename. $ wc -l file01.txt 5 file01.txt.
  2. To omit the filename from the result, use: $ wc -l < file01.txt 5.
  3. You can always provide the command output to the wc command using pipe. For example:
James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest