3 ms·
I first learned awk precisely to replace cut. Not being able to reorder fields make it an especially narrow tool. Is there anything from cut I'm missing out on?
by kjeetgill 8y ago
I first learned awk precisely to replace cut. Not being able to reorder fields make it an especially narrow tool. Is there anything from cut I'm missing out on?
- mmt 8y ago> Is there anything from cut I'm missing out on? It's a narrow tool. Other than the inherent advantage this brings in clarity/simplicity in a script, there's nothing else to it.
- kazinator 8y agoScripts in which you have both cut and awk are not simpler or clearer than ones in which you only use awk.
- mmt 8y agoAlthough I completely agree with this for any given "one-liner" or pipeline (even if it's multiple lines), I don't believe the mere use of awk in one place in the script means using cut elsewhere isn't simpler/clearer there. Consider a script that originally had now awk but just a field=$(somecmd | cut -d: -f3) but now has been modified to have awk elsewhere. Did the above just become less simple or clear? If so, is it worth changing it to the below for clarity? Does it matter if the awk predates the cut, instead? field=$(somecmd | awk -F: '{print $2}') I say "no" to both, although I do recognize the argument for just using the same, consistent tool everywhere, instead.