Skip to content
Archive of posts filed under the faq category.

“In-place” editing of files

Temporary files don't bite, so just use them.

Joining files with awk

Join lines from files based on keys

Awk pitfall: string concatenation

This is a bit of a dark corner of awk. This beast is string concatenation. There is a classical example in the awk FAQ number 28: $ awk 'BEGIN { print 6 " " -22 }' 6-22 Where did the space go? First, " " -22 is evaluated, in numeric context, yielding 0-22 = -22. [...]

Removing newlines in text files

A task that comes up every so often, for some reason

“Zero or more”

This usually comes up in a form similar to "I'm running this code: $ echo "foobar 123" | sed 's/[0-9]*/blah/' blahfoobar 123 but I don't get the expected result!" (which they think should be "foobar blah"). The result they get is instead as shown above. Why is that? Remember that the star quantifier "*" means [...]