fbpx nl Command in Linux: Number Lines in Text Files | Certificação Linux

nl Command in Linux: Number Lines in Text Files in Terminal

📅 01/01/2019 ⏱ 2 min ✍️ Uira Ribeiro
Linuxcommands
nl Command in Linux: Number Lines in Text Files in Terminal
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The nl command in Linux (number lines) is used to number the lines of a file. The command considers special conditions for the header and footer of the file.

The frequently used options are:

  • -h sub-option: Used to format the text header. The default is not to number the header;
  • -b sub-option: Used to format the body of the text. The default is to number only non-empty lines;
  • -f sub-option: Used to format the text footer. The default is not to number the footer.

The sub-options are:

  • A: Number all lines;
  • t: Number only the filled ones;
  • n: Do not number the lines.

Example:

Suppose that arquivo.txt has the following content:

\:\:\:
Relatório de Notas e Frequência dos alunos de Engenharia de Software
—————————————————————————————————
Nome Nota Freq. Resultado
—————————————————————————————————
\:\:
Carlos Torres 8,5 80% Aprovado
José Antônio 10,0 100% Aprovado
Maria de Lourdes 10,0 100% Aprovado
Mário Cabral 9,5 100% Aprovado
\:
—————————————————————————————————

And using the nl command:

$ nl arquivo.txt

The result will be:

Relatório de Notas e Frequência dos alunos de Engenharia de Software—————————————————————————————————Nome Nota Freq. Resultado—————————————————————————————————1 Carlos Torres 8,5 80% Aprovado2 José Antônio 10,0 100% Aprovado3 Maria de Lourdes 10,0 100% Aprovado4 Mário Cabral 9,5 100% Aprovado—————————————————————————————————

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp