Plan 9 from Bell Labs’s /usr/web/sources/contrib/alltom/f

Copyright © 2009 Alcatel-Lucent.
Distributed under the Lucent Public License version 1.02.
Download the Plan 9 distribution.


#!/bin/awk -f
# f - format text into 72-char lines
# taken from Brian Kernighan's COS 333 slides

/./ { for (i = 1; i <= NF; i++) addword($i) }
/^$/ { printline(); print "" }
END { printline() }

function addword(w) {
	if (length(line) + length(w) > 72)
		printline()
	line = line space w
	space = " "
}

function printline() {
	if (length(line) > 0)
		print line
	line = space = ""
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2009 Alcatel-Lucent. All Rights Reserved.
Comments to webmaster@plan9.bell-labs.com.