FTJ
← Blog
Text

How to Add Line Numbers to Text (3 Ways)

Referencing line 42 of a file is easier with actual numbers. Here's how to add them — plus a free online tool.

# Line Number Adder: Number Your Text Lines Instantly

When you share a code snippet, paste a log file, or reference a specific line in a document, line numbers make communication precise. "Check line 47" is clearer than "look about halfway down." FreeToolJet's Line Number Adder prepends line numbers to any text with full control over formatting.

Customization Options

  • Start at: Begin numbering from any integer (default: 1). Useful when referencing a range that starts mid-file.
  • Separator: Choose between colon-space (: ), period-space (. ), tab, or any custom separator.
  • Padding: Set to 0 for auto-width (pads to the width of the largest number), or specify a fixed width.

Common Use Cases

  • Code reviews: Paste code and share with line numbers for precise feedback.
  • Bug reports: Reference exact line numbers in error logs.
  • Documentation: Add line-numbered code examples to articles and guides.
  • Education: Number lines in assignments and exercises.

Tips

  • Use auto-padding (width 0) so all numbers align neatly regardless of total lines.
  • For Markdown documents, use . as separator to match GitHub-style line references.
  • Combine with Sort Lines to organize before numbering.

Related Tools


Want more tools? Explore our full collection at FreeToolJet - we're constantly adding new utilities based on developer feedback.

## Why Add Line Numbers

Line numbers are essential in several contexts:

  • Code reviews: Referencing line 42 is clearer than "about halfway down"
  • Error reporting: Stack traces and compiler errors use line numbers to pinpoint issues
  • Educational materials: Tutorials and textbooks number lines for easy reference
  • Legal documents: Contracts and statutes use line numbers for citations
  • Log analysis: Numbered lines make it easier to discuss findings in a team
  • Diff tools: Many comparison tools work better with numbered input

Line Numbering Formats

Different contexts use different formats:

  • Plain: 1: text — Simple, works everywhere
  • Padded: 1: text — Right-aligned numbers, good for files with 100+ lines
  • Tab-separated: 1\ttext — Easy to parse programmatically
  • Dot separator: 1. text — Common in documentation
  • Bracketed: [1] text — Used in academic and legal contexts
  • Vim-style: 1 text — Right-aligned, no separator, Vim default

Programmatic Line Numbering

Most text editors and tools can add line numbers automatically:

  • VS Code: Toggle line numbers in settings (enabled by default). Copy with line numbers using the "Copy with Syntax Highlighting" extension.
  • cat: cat -n file.txt numbers lines in terminal output
  • awk: awk '{print NR": "$0}' file.txt for custom format
  • Python: for i, line in enumerate(text.split('\n'), 1): print(f"{i}: {line}")
  • sed: sed '=' file.txt inserts line numbers on separate lines

Try These Tools

More Articles