Hacker News new | ask | show | jobs
by Moyamo 4141 days ago
Even though, the ruby one-liner seems more legible, it is a lot longer (and probably a lot slower).

In this case I don't see what's wrong with the sed, awk or grep commands (fast and short).

To explain how they work

    sed -i '/^$/d' input.txt # for every line matching '^$' (empty line) apply 'd' (delete the line).
    grep -v '^$' # print every line not matching '^$' (empty line)


    awk 'NF' input.txt
    # 'NF' stand for Number of Fields (this is equivalent to number of columns
    # in a table). If the number of fields is 0 the line must be empty.  In awk
    # 0 is false and non-zero is true. Thus when 'NF' is non-zero (non-empty)
    # it is true, and the line will be printed.