| Crates.io | line-rs |
| lib.rs | line-rs |
| version | 0.1.0 |
| created_at | 2025-08-11 20:36:22.399743+00 |
| updated_at | 2025-08-11 20:36:22.399743+00 |
| description | Extract lines from files without hacks! |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1790873 |
| size | 17,964 |
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.

line-rs supports three main ways to select lines:
line -n=5 file.txt
line -n=2:4 file.txt # 2, 3, 4
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
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:
line -n=3:7:2 # 3, 5, 7
line -n=5:3:-1 # 5, 4, 3
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
More about that soon
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"}
More about that soon
More about that soon
# 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 -
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.
MIT
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).