Use the Unix cat command to add line numbers to text

Source: Internet
Author: User

Sometimes you need to add line numbers to the text, which you can do with the Unix cat command. The use of the

Cat command is as follows:
 name
          cat-concatenate, Copy, and print files
 synopsis
          cat [-BENRSTUV] File ...
Options
      Cat recognizes the following options:
           -b   Omit Line numbers to blank lines when-n option is
  & nbsp;             specified. If This option is specified, the-n the option is
                 automatically selected.

-e Print A $ character at the "End of" (prior to the
New-line). If This option is specified, the-v option is
Automatically selected.

-N Display output lines preceded by line numbers, numbered
Sequentially from 1.

          -r   Replace multiple consecutive empty Lines with one empty
                 Line, so this there is never more than one empty line
         &nb sp;      between lines containing characters.

          -s   Silent option.  cat Suppresses Error messages about non-
                 Existent files, identical input and output, and write
                 errors.  Normally, input and output files cannot have
   & nbsp;            identical names unless the file is a special File.

          -t   Print each tab character as ^i and Form feed character as
                 ^l.  If This option is specified, the-v the option is
                 automatically selected.

-U does not buffer output (handle character-by-character).
Normally, output is buffered.

Cat-n can add line numbers, Cat-b can also add line numbers, but empty lines are ignored.
If the following command can add blank lines for File1, enter as File2 (blank line plus line number): Cat-n file1 > File2

If the following command can add blank lines for File1, enter as File2 (no line number for blank lines): Cat-b file1 > File2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.