On Wed, 17 Jun 2009 10:55:28 -0700 (PDT), chloe K <chloekcy2...@yahoo.ca> wrote: > Hi > 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
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 keram...@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 keram...@ceid.upatras.gr | \ awk '{print "Dear: ", $1; print "Address:", $2}' Dear: giorgos Address: keram...@ceid.upatras.gr A single line of awk is vastly more readable than the equivalent sed expression in this case. _______________________________________________ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"