3 ms·
Its common as in the OP to see awk recommended for something as simple as extracting a column from tab or space-separated values. IMO, its quite a bit of typin
by 1vuio0pswjnm7 5y ago
Its common as in the OP to see awk recommended for something as simple as extracting a column from tab or space-separated values. IMO, its quite a bit of typing to do on the fly at a command prompt. Performance-wise, it could be significantly slower that other utilities that are equally as ubiquitous as awk.
echo one two three|awk '{print $2}'
Are there other ways to do this. Are they faster.
cat > awc
#!/bin/sh
test $# -eq 1||exit
exec tr \\40 \\11|exec cut -f "$1"|exec tr \\11 \\40
^D
echo one two three|awc 2
Test it on a file to see if it is faster than awk.
time awk '{print $2}' file
time awc 2 < file
- mappu 5y agoIs the exec needed in the pipeline?
- 1vuio0pswjnm7 5y agox(){ tr \\11 \\40;} x|cut -f "$1"|x
- 1vuio0pswjnm7 5y agoCorrection x(){ tr \\40 \\11;} y(){ tr \\11 \\40;} x|cut -f "$1"|y