Shell trick #1: Numbering lines in text files
Hi, today I'll present you something new. It is an experiment and I'd be curios whether you like it. I've started a little series of ttyrecs. That means, I've recorded a little tip or trick on the console and uploaded it to PLAYterm so it can be easily played back in the browser. I thought it could be useful to do a little command line gymnastics.
Today I'll show you three ways how you can number lines in text files. We'll do that with cat, nl and vim.
Note: you need JavaScript enabled in order to play the ttyrec. Also make sure you're not using SSL HTTPS connections with scripts from non-HTTPS sites do not work in some browsers such as Chromium.
Let me know what you think about it. If you like this series, I'l drop in some more episodes from time to time.
Update 1:25PM
Okay, first run, first problems. Looks as if all the output vanishes and only the current command line is visible. Let's see if we can fix this.
Update 1:41PM
Seems to be a problem with zsh. If the PLAYterm developer can't fix it, I need to record it again in bash.
Update 8:26PM
I've written to the developer that ttyrecs recorded with a zsh shell don't work properly with his player. Let's hope he'll respond soon. For the time being I've uploaded the raw ttyrec to the server. Download it, install the package ttyrec, set your terminal to a size of 80x24 and execute ttyplay 01_number_lines_in_file.tty
.
I think, it's generally a good idea to upload all the ttyrecs so I'll do that for future records as well, regardless of whether PLAYterm functions properly or not.