From owner-freebsd-questions@FreeBSD.ORG Wed Jun 17 21:07:10 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1078C1065670 for ; Wed, 17 Jun 2009 21:07:10 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id BB5608FC14 for ; Wed, 17 Jun 2009 21:07:09 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id n5HL78qu051867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 17 Jun 2009 16:07:09 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id n5HL78WP085132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 17 Jun 2009 16:07:08 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.3/Submit) id n5HL77Og085127; Wed, 17 Jun 2009 16:07:07 -0500 (CDT) (envelope-from dan) Date: Wed, 17 Jun 2009 16:07:07 -0500 From: Dan Nelson To: chloe K Message-ID: <20090617210703.GC12966@dan.emsphone.com> References: <974960.33077.qm@web57412.mail.re1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <974960.33077.qm@web57412.mail.re1.yahoo.com> X-OS: FreeBSD 7.2-STABLE User-Agent: Mutt/1.5.19 (2009-01-05) X-Virus-Scanned: ClamAV version 0.94.1, clamav-milter version 0.94.1 on email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Wed, 17 Jun 2009 16:07:09 -0500 (CDT) X-Scanned-By: MIMEDefang 2.45 Cc: freebsd-questions@freebsd.org Subject: Re: sed help X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2009 21:07:10 -0000 In the last episode (Jun 17), chloe K said: > I have a file. list.txt (two columns) >   > column1    column2 > name        address >   > I need to put in the letter file letter.txt eg: >   > Dear: Chloe > Address: CA >   > Can I use this >   > for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt Try: cat list.txt | while read name address ; do sed -e "s/Chloe/$name/ ; s/CA/$address/" < letter.txt > letter.$name.txt done You need the "while read" part so that you loop once per line. Your code would have looped once per word in the input file. You also need double-quotes on your sed line because $variable expansion isn't done inside single-quotes. If your names have spaces in them, consider swapping the name and address in your input file, since "read" splits on spaces and assigns the remainder of the line to the last variable listed. -- Dan Nelson dnelson@allantgroup.com