line-rs

Crates.ioline-rs
lib.rsline-rs
version0.1.0
created_at2025-08-11 20:36:22.399743+00
updated_at2025-08-11 20:36:22.399743+00
descriptionExtract lines from files without hacks!
homepage
repository
max_upload_size
id1790873
size17,964
Ahmad Alsaleh (Ahmad-Alsaleh)

documentation

README

line-rs

line-rs is a simple command-line tool to extract specific lines from a text file without hacks like head -n 5 filename.txt | tail -n +2.

demo will be here soon

Features

Line Selection

line-rs supports three main ways to select lines:

  1. Select a single line:
line -n=5 file.txt
  1. Select a range of lines (both ends are included):
line -n=2:4 file.txt # 2, 3, 4
  1. Select multiple specific lines:
line -n=2,4,6 file.txt

You can also combine the above! The command bellow selects the line 2 and the range 4:6.

line -n=2,4:6 file.txt # 2, 4, 5, 6

Advanced Line Selection

line-rs supports line selection in a powerful way. If you are familiar with Python syntax, the following should be familiar as well:

  • Negative indexing:

    • Select the last line:

      line -n=-1
      
    • From line 3 up to the 2 line from the end:

      line -n=3:-2
      
  • Unbounded Ranges:

    • From line 3 up to the end of the file:

      line -n=3:
      
    • From the begining of the file up to line 9:

      line -n=:9 # equivalent to 1:9
      
    • All lines, equivalent to cat:

      line -n=:
      
  • Steps:

    • From line 3 up to 9, jumping two lines at a time:
      line -n=3:7:2 # 3, 5, 7
      
    • From line 9 up to 3, jumping backwards:
    line -n=5:3:-1 # 5, 4, 3
    
    • Reverse all lines:
    line -n=::-1
    

You can also skip lines easily:

  • Print all line except 5 and 7:

    line --skip=5,7
    
  • Print line 2 onwards, skipping lines 6, 7, and 8:

    line -n=2: --skip=6:8
    

Pretty Printing

More about that soon

Json Output

The output can be serialized as JSON, useful for piping and scripts

line -n=2,4 --json # one line, useful for piping
line -n=2,4 --pretty-json

Output:

{
  "source": "file.txt", // or "stdin"
  "lines": [
    { "number": 2, "content": "hi" },
    { "number": 4, "content": "hello" }
  ]
}
line -n=2,4 --array

Output

["hi", "hello"]
line -n=2,4 --json-line

Output

{"number":2,"content":"foo"}
{"number":4,"content":"bar"}

🔧 Installation

More about that soon

Using Cargo

Using pip

Using apt

Using brew

Shell Complition

More about that soon

Examples

# Print line 5
line -n=5 notes.txt

# Print lines 3 to 7
line -n=3:7 notes.txt

# Print lines 2, 4, and 6
line -n=2,4,6 notes.txt

# Print line 1 from stdin
echo -e "a\nb\nc" | line -n=1 -

🛠 Motivation

This tool simplifies extracting lines from a file or stream without relying on brittle chains like:

cat file.txt | head -n=4 | tail -n=1

line-rs gives you a cleaner and more flexible alternative.


📃 License

MIT


💬 Feedback

Feel free to open issues or suggestions on GitHub.


Let me know if you'd like me to add sections for contributing, testing, or packaging (e.g., Debian, Homebrew, etc).
Commit count: 0

cargo fmt