Hacker News new | past | comments | ask | show | jobs | submit login

The first line they start with is utter nonsense. find -print0 will not produce lines, but records (or strings) separated by NUL. But grep is a tool working with lines (separated by LF). No mystery that it cannot work.

Using -print0 is necessary if you have filenames containing LF chars. Otherwise just use -print and grep and everything should be fine.

Now how do we handle NUL separated records? That required a bit of thinking, the Unix world is based so much on lines. Without extensive testing the following awk program seems to work:

    BEGIN       { RS = "\0" }
    $0 ~ regexp
Call with

    awk -v 'regexp=what I search for'
In their script that would be

    awk -v "regexp=$1"

Edit: Credits for s/whitespace/LF chars/ go to user hnfong





When grepping for filenames print0 is needed only when the files have new lines in them. (Which is quite degenerate.) grep works fine with spaces and tabs in the stdin

Thanks! Updated.



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

Search: