3 ms·
awk is so much better than sed to learn given its ability, the only unix tool it doesn't replace is tr and tail, but other than that, you can use it instead of
by nmz 11mo ago
awk is so much better than sed to learn given its ability, the only unix tool it doesn't replace is tr and tail, but other than that, you can use it instead of grep, cut, sed, head.
- stevekemp 11mo agoI think you could replace tail with awk, if you absolute needed to. This is a naive attempt: cat /etc/passwd | \ awk -v n=10 '{ lines[NR] = $0 } END{ for (i = NR - n + 1; i <= NR; i++) if (i > 0) print lines[i] }'
- nmz 11mo agoYou can, sure, but, tail seeks to EOF and then goes back until it finds "\n", awk cannot seek, so you must do what you did there, that means the bigger the file the longer the time. And there's also tail -f, how would you go about doing that? a while loop that sleeps and reopens the file? yuck