3 ms·
that is not equivalent because awk will remove trailing/leading space/tab/newlines (newlines come into play with a different record separator) whereas, tr will
by asicsp 7y ago
that is not equivalent because awk will remove trailing/leading space/tab/newlines (newlines come into play with a different record separator)
whereas, tr will still leave a trailing/leading space
for example:
$ echo ' a b c ' | tr -s ' ' | cut -d ' ' -f2
a
$ echo ' a b c ' | awk '{print $2}'
b
and by default awk splits on space/tab/newlines, whereas in cut example above, you get only space as delimiter
cut has its uses and will be faster than awk, but it depends on the problem being solved
- chme 7y agoYou are right it depends on the specific use case. It possible to use `xargs -L 1` to trim the separators, but then you would also add `findutils` as deps. I just wanted to point out that keeping the dependencies of scripts in mind when programming is also important.