How do I print line numbers but reset line counter at empty line?
1
vote
4
answers
520
views
I have a file.txt containing:
this is the first
second line
not last line
fourth but first
second in list
seventh in file
seventh with nl
Normally I would just cat
and pipe |
it into nl
like so:
$> cat file.txt | nl
1 this is the first
2 second line
3 not last line
4 fourth but first
5 second in list
6 seventh in file
7 seventh with nl
But I need the line numbers to reset when it encounters an empty line like so:
$> alias_or_function file.txt
1 this is the first
2 second line
3 not last line
1 fourth but first
2 second in list
3 seventh in file
4 seventh with nl
How could I do this using a quick function or alias in my ~/.zshrc
?
Asked by ntruter42
(197 rep)
Aug 22, 2020, 04:17 AM
Last activity: Mar 3, 2025, 07:36 PM
Last activity: Mar 3, 2025, 07:36 PM