I made a tool back in college called “line” for outputting ranges of line or column numbers.
I got tired of piping head into tail and found it simpler.
Examples:
line file.txt 5 to 9
cat file.txt | line —column 4 to 20
I thought “line” was very Unix sounding and kinda cute, but like a lot of these projects would never make its way into the gnu utils so I thought what’s the point. That and of course to a beginner Awk user, those kind of operations are child’s play. I thought about csv and printing lines between matching words, but it’s all about KISS.
I'd much prefer an ecosystem of interlocking small commands with uniform options than using classic UNIX do-everything tools such as awk. These generally have terrible syntax that's impossible to remember. If I'm gonna drop to a sublanguage other than the shell, I'll use something sane like Python.
To me it feels like someone could rethink the unix tools in the way you're talking about, and maybe it could become a successful and widely-adopted project. Because a suite of tools like this could live alongside the old unix stuff.
The main challenge to doing this well is having good taste and experience. It may be that if you really tried to do this, you'd face tons of UX challenges, and you'd find that tools like awk really were in the sweet spot already.
awk is a lot better at what it does than Python though, and much easier too.
Even something simple as "cmd | awk {print $1}" in awk is something like:
import sys, re
for line in sys.stdin.read().split('\n'):
s = re.split('\s+')
if len(s) > 0:
print(s[0])
else:
print()
And I probably got that incorrect as it's probably not the way to read stdin (it's been a while since I programmed Python).
I can list many gripes with Unix tools, but "awk bad" isn't on that list. It's a small language that solves a very specific problem, and does that surprisingly well. The syntax is about as simple as it gets – no idea how it's "terrible" or "impossible to remember", and it's certainly not "insane" as you seem to be suggesting.
It's fun to write your own tools! (Scratch your own itch and all that.)
It sounds like your "line" replicates a use of sed that I use all the time, printing a contiguous range of lines.
The example:
line file.txt 5 to 9
can be:
sed -n '5,9p' file.txt
You mention using awk, which totally works, but to me is much less ergonomic.
You don't explain what line's "--column" option does so I'm not sure what the equivalent of that might be. That might be where awk comes into its own ... :)
> [...] and printing lines between matching words
This is the same sed command as above, but using regular expressions for the address part:
sed -n '/^func doit/,/^}$/'
will print just the function called "doit" (in properly formatted go).
Could you (I mean "one") design a "friendlier" (or more "beginner friendly") user interface than sed presents? Yes, obviously (you did exactly that). But unlocking the power (or even just beginning to "unlock" the power) of the standard tools (sed, awk, grep, tr, cut, paste, find, xargs, ...) can get you a really long way. Of course, the initial problem is how to know that one of those tools can solve the problem you have in your head.
("Bonus" sed content: replace "head":
Instead of
head -n 5
do
sed 5q
To replace tail you need tac (or "tail -r", haha))
Idk, the amount of Unix that GNU and BSD accepted as a bare environment, the range is single purpose programs like tail and mini interpreters which are powerful but require a lot of skill. If I worked in system administration, and I HAD to use shell, I'd hold onto Awk for dear life. But I don't, so it's sort of this ancient swiss army knife.
I got tired of piping head into tail and found it simpler.
Examples:
line file.txt 5 to 9
cat file.txt | line —column 4 to 20
I thought “line” was very Unix sounding and kinda cute, but like a lot of these projects would never make its way into the gnu utils so I thought what’s the point. That and of course to a beginner Awk user, those kind of operations are child’s play. I thought about csv and printing lines between matching words, but it’s all about KISS.