BEGIN {
i=0
l=""
}
{
if (i == 3) {
i=1
print l
l=$0
}
else {
if (i == 0) {
l=$0
}
else {
l=l" "$0
}
i=i+1
}
}
END {print l}
This script can be generalized to combine N lines of output by replacing the line:if (i == 3) {
with
if (i == N) {
where N is a variable or the desired number of lines to combine. This can eliminate a tedious job like deleting newlines from a file (particularly when copying some PDF tables into a text editor like notepad, emacs, or vi) and make a task part of a larger and more automated process. Replacing $0 with $1..$n will only concatenate the nth field. This is easy to run on UNIX/Linux (since awk is included with most distributions), but on Windows it requires Cygwin (which I use) or a native port of the GNU awk utility (check out the GNUWin32 project on SourceForge).
No comments:
Post a Comment