#!/bin/awk -f # This is part of Phil's AWK tutorial at http://www.bolthole.com/AWK.html # This program expects an LDIF file as input. ldifs have annoying # linewrapping, in that if a line begins with a space, it is a continuation # of a previous line. This program undoes that, and reconstructs the data # as a single continuous line where appropriate. # This is useful as preprocessing before transforming the data into a # different format (such as coaxing it into a real database) # # This program is a little "backwards" in order, for ease of programing. # The first line actualy deals with the "continuation" case. It strips # off the initial space, and saves the result. # The second one is a fallthrough, which presumes it is a "normal" line. # It first prints out any saved line, then resets the safe buffer to # contain the current line. /^ / {addon=substr($0, 2, length()); BUFFER=BUFFER""addon; next;} {print BUFFER; BUFFER=$0; } #And dont forget to flush your internal buffers when done! END {print BUFFER }