Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Is the exec needed in the pipeline?


       x(){ tr \\11 \\40;}
       x|cut -f "$1"|x


Correction

       x(){ tr \\40 \\11;}
       y(){ tr \\11 \\40;}
       x|cut -f "$1"|y




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: