From owner-freebsd-questions@FreeBSD.ORG Wed Jun 17 21:17:53 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 C679A106566C for ; Wed, 17 Jun 2009 21:17:53 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from poseidon.ceid.upatras.gr (poseidon.ceid.upatras.gr [150.140.141.169]) by mx1.freebsd.org (Postfix) with ESMTP id 2BD648FC0A for ; Wed, 17 Jun 2009 21:17:53 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from mail.ceid.upatras.gr (unknown [10.1.0.143]) by poseidon.ceid.upatras.gr (Postfix) with ESMTP id 00BDAEB539F; Thu, 18 Jun 2009 00:17:51 +0300 (EEST) Received: from localhost (europa.ceid.upatras.gr [127.0.0.1]) by mail.ceid.upatras.gr (Postfix) with ESMTP id 0C1A94503F; Thu, 18 Jun 2009 00:17:51 +0300 (EEST) X-Virus-Scanned: amavisd-new at ceid.upatras.gr Received: from mail.ceid.upatras.gr ([127.0.0.1]) by localhost (europa.ceid.upatras.gr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lFk07NV+6ytP; Thu, 18 Jun 2009 00:17:50 +0300 (EEST) Received: from kobe.laptop (adsl105-76.kln.forthnet.gr [77.49.224.76]) by mail.ceid.upatras.gr (Postfix) with ESMTP id B83FF45088; Thu, 18 Jun 2009 00:17:50 +0300 (EEST) Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.3/8.14.3) with ESMTP id n5HL0NlX018303; Thu, 18 Jun 2009 00:00:23 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.3/8.14.3/Submit) id n5HL0MoY018302; Thu, 18 Jun 2009 00:00:22 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: chloe K References: <974960.33077.qm@web57412.mail.re1.yahoo.com> Date: Thu, 18 Jun 2009 00:00:22 +0300 In-Reply-To: <974960.33077.qm@web57412.mail.re1.yahoo.com> (chloe K.'s message of "Wed, 17 Jun 2009 10:55:28 -0700 (PDT)") Message-ID: <873a9yshi1.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable 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:17:54 -0000 On Wed, 17 Jun 2009 10:55:28 -0700 (PDT), chloe K w= rote: > Hi > I have a file. list.txt (two columns) > =A0 > column1=A0=A0=A0 column2 > name=A0=A0=A0=A0=A0=A0=A0 address > =A0 > I need to put in the letter file letter.txt eg: > =A0 > Dear: Chloe > Address: CA > =A0 > Can I use this > =A0 > for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt No that won't work. sed does 'stream editing' to its own input file, so you have to redirect each output for *every* loop iteration. But I don't think this is a good method of solving this problem, because you only have one input file and one output file. See what the following does, to give you can idea: $ echo giorgos keramida@ceid.upatras.gr | sed -e 's/^\([^ ]*\)[ ]*\(.*\)$/\ Dear: \1\ Address: \2\ /' NOTE: If you really want to work effectively with sed, please take a bit of time to read the manpage of sed(1) and ed(1), paying careful to the parts about: (1) regular expressions, (2) character classes, and (3) the rules of character quoting. It's also worth noting that you don't _have_ to use sed for this specific problem, because there are other tools more suitable for processing data in columns, i.e. awk(1): $ echo giorgos keramida@ceid.upatras.gr | \ awk '{print "Dear: ", $1; print "Address:", $2}' Dear: giorgos Address: keramida@ceid.upatras.gr A single line of awk is vastly more readable than the equivalent sed expression in this case.