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

    cat *.pgn | grep "Result" | sort | uniq -c
This pipeline has a useless use of cat. Over time I've found cat to be kind of slow as compared to actually passing a filename to a command when I can. If you rewrite it to be:

    grep -h "Result" *.pgn | ...
It would be much faster. I found this when I was fiddling with my current log processor to analyze stats on my blog.


Yes, it does. Spoiler alert: I remove it at the end. ;)


Still I like the article. I just learned about useless use of cat the hard way. The biggest way I learned was

    cat /dev/zero | pv > /dev/null

    pv > /dev/null < /dev/zero
The second one is much faster.


   Argument list too long!


Then do:

find -name \*.pgn -print0 | xargs -0 grep -h "Result"

Each grep invocation will consume a maximum number of arguments, and xargs will invoke the minimum number of greps to process everything, with no "args too long" errors.


Increase your stack size then.

    ulimit -s 65536
https://unix.stackexchange.com/a/45584/115135




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

Search: