Date: Thu, 18 Jun 2009 00:00:22 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: chloe K <chloekcy2000@yahoo.ca> Cc: freebsd-questions@freebsd.org Subject: Re: sed help Message-ID: <873a9yshi1.fsf@kobe.laptop> 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)") References: <974960.33077.qm@web57412.mail.re1.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 17 Jun 2009 10:55:28 -0700 (PDT), chloe K <chloekcy2000@yahoo.ca> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?873a9yshi1.fsf>