Joining Textlines containing "Key: Text."
Chris Torek
chris at umcp-cs.UUCP
Sat Nov 9 19:31:08 AEST 1985
The original example in <429 at unido.UUCP> had, if I recall correctly,
repeated keys that were not in sequence. If all your keys are in
sequence then the associative array feature of awk is unnecessary
and is indeed wasteful, as you point out.
For another example, here is the last part of my current `generic
makefile'. It runs through a set of programs, each assumed to
consist of one `.c' file, and finds what they `#include'. The
output of `cc -M', which of course consists of `key: text' lines,
is joined into lines no more than 78 columns long. This is then
inserted into the makefile itself, so that it will have an accurate
dependency list---including <sys/foo.h> files, which have here a
tendency toward rapid change. The -M option is available only in
late 4.2 and 4.3 `cc's, unfortunately.
depend:
for i in ${SUBDIR}; do (cd $$i; make ${MFLAGS} depend); done
for i in ${STD} ${NSTD} ${KMEM} ${SETUID}; do \
cc -M $$i.c | sed -e 's/\.o//' | awk '{ if ($$1 != prev) { \
if (rec != "") print rec; rec = $$0; prev = $$1; } \
else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
else rec = rec " " $$2 } } \
END { print rec }'; done >makedep
echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
echo '$$r makedep' >>eddep
echo 'w' >>eddep
cp Makefile Makefile.bak
ed - Makefile < eddep
rm eddep makedep
echo '# DEPENDENCIES MUST END AT END OF FILE' >>Makefile
echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>Makefile
echo '# see make depend above' >>Makefile
# Files listed in ${NSTD} have explicit make lines given below.
# DO NOT DELETE THIS LINE -- make depend uses it
# DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# see make depend above
--
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