Path: utzoo!attcan!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.wizards Subject: Re: This is strange... Keywords: sed awk pipe Message-ID: <1848@piraat.cs.vu.nl> Date: 22 Dec 88 09:59:33 GMT References: <1652@ektools.UUCP> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 49 mcapron@ektools.UUCP (M. Capron) writes: \#!/bin/sh \for i in *.c \do \#Place a list of include files in $incs seperated by spaces. \#CODE A or CODE B goes here. \ echo "$i : $incs" \done \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'` Compare your example with the following: % echo -n 'merry Xmas' | sed 's/.*/&, happy new year/' % Now get rid of the `-n' and suddenly everything works! The problem: sed won't do anything with unfinished lines! You explicitly didn't append a newline in the awk script. See how far that got you! :-) Solution: incs=`egrep '^#[ ]*include[ ]*"' $i | awk ' {printf "%s ", $2} END {printf "\n"}' | sed 's/"//g'` BTW, it's not forbidden to use newlines between backquotes! Another interesting case: $ cat > merry_Xmas happy 1989 $ card=`cat merry_Xmas` $ echo $card happy 1989 $ echo "$card" happy 1989 Csh hasn't got this anomaly. -- if (fcntl(merry, X_MAS, &a)) |Maarten Litmaath @ VU Amsterdam: perror("happy new year!"); |maart@cs.vu.nl, mcvax!botter!maart