| Crates.io | lineno |
| lib.rs | lineno |
| version | 0.1.0 |
| created_at | 2025-02-05 14:22:57.92662+00 |
| updated_at | 2025-02-05 14:22:57.92662+00 |
| description | Display specific lines or ranges of lines of a file |
| homepage | https://github.com/adam-gaia/lineno |
| repository | https://github.com/adam-gaia/lineno |
| max_upload_size | |
| id | 1544040 |
| size | 117,507 |
Display specific lines or ranges of lines of a file
Suppose you need lines 10 to 15 of file 'file.txt' as part of a greater pipeline.
You can use head and tail together in with head -n 15 file.txt | tail -n 6.
While that's relatively easy, lineno makes it even easier:
$ lineno -f file.txt 10..15
foo
bar
baz
qux
quux
didgeridoo
What if we want lines 10 through 15 and line 26?. My unix-foo isn't good enough to do that in a single pipeline off the top of my head. But of course its trivial with lineno:
$ lineno -f file.txt 10..15 26
foo
bar
baz
qux
quux
didgeridoo
supercalifragilisticexpialidocious
(My contrived-example-foo has always outpaced my unix-foo)
lineno takes an arbitrary number of filters and returns lines matching those filters.
Filters any combo of
10$ lineno -f ./tests/foo.txt 2
bar
1:10$ lineno -f ./tests/foo.txt 1:3
foo
bar
baz
Both the upper and lower bounds on ranges are inclusive
Ranges may either be specified with a ':' or '..' (1..10 and 1:10 are equivalent) (like the head util)
Omitting the upperbound returns all lines from the lowerbound to the end of the file (24..) (like the tail util)
$ lineno -f ./tests/rocket.txt 8..
3
2
1
blast off!
$ lineno -f ./tests/rocket.txt ..4
10
9
8
7
Multiple filters may be specified by commas or whitespace
$ lineno -f file.txt 3 2 1 10:12
long
text
innoculous
foo
bar
baz
$ lineno -f file.txt 23 23 23 25
spam
spam
spam
eggs
Running lineno without any filters cats the file (outputs the file unmodified)
$ lineno -f ./tests/small.txt
line 1
line 2
line 3
which, btw, is the same as an empty range (idk why one would want to do that instead of using cat, but it's possible)
$ lineno -f ./tests/small.txt ..
line 1
line 2
line 3
If no file is specified, lineno will read from stdin
$ cat ./tests/small.txt | lineno 3
line 3
Oh hey, that last example is a useless use of cat. Lets make it even more useless for fun
$ lineno -f ./tests/small.txt .. | lineno 3
line 3
-f, --file <file>
You've already seen the '-f' option to provide an input file:$ lineno -f ./tests/small.txt
line 1
line 2
line 3
-n,--number
The '-n' option displays line numbers along with the line's content:$ lineno -f ./tests/small.txt -n
1: line 1
2: line 2
3: line 3