This is strange...

James Logan III logan at vsedev.VSE.COM
Sat Dec 24 02:10:32 AEST 1988


In article <1652 at ektools.UUCP> mcapron at ektools.UUCP (M. Capron) writes:
# 
# CODE A: This works.
# incs=`egrep '^#[         ]*include[     ]*"' $i | awk '{printf "%s ", $2}'`
# incs=`echo "$incs" | sed 's/"//g'`
# 
# CODE B: This does not work.
# incs=`egrep '^#[         ]*include[     ]*"' $i | awk '{printf "%s ", $2}' | sed 's/"//g'`
# 

Someone else already answered your question correctly, but I have another
version for you that handles all of the following cases:

	#include <file>
	#include "file"
	#  include <file>
	#  include "file"

and runs a little faster, since it is all contained in one awk script
and does not required additional processing by sed.

incs=`
	awk '
		/^#[ 	]*include[ 	]*/ {
			if (NF == 3) {
				# line is like "# include <file>"
				INCFILE=$3;
			} else {
				# line is like "#include <file>"
				INCFILE=$2;
			}
			print substr(INCFILE, 2, length(INCFILE) - 2);
		}
	' <$i;
`;

			-Jim
-- 
Jim Logan		logan at vsedev.vse.com
(703) 892-0002		uucp:	..!uunet!vsedev!logan
			inet:	logan%vsedev.vse.com at uunet.uu.net



More information about the Comp.unix.wizards mailing list