Joining Textlines containing "Key: Text."

Chris Torek chris at umcp-cs.UUCP
Fri Nov 8 19:26:47 AEST 1985


Sounds like a problem for `awk'.  If your separator is :, use -F:;
or if the first `word' will do, that is unnecessary.  Here is an
awk script to take <key> <space> <value> lines and join together
all the <value>s:

# $1 is the key, $2 through $NF are the values
NF > 0 {
	if (NF == 1)
		key[$1] = key[$1] "";
	else
		for (i = 2; i <= NF; i++)
			key[$1] = key[$1] " " $i;
}

END {
	for (i in key)
		print i key[i];
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix mailing list