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 ? Thank you for your help ? ? ? ? ? __________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20090617/84cbec60/attachment-0001.html>
> Can I use this > > for i `cat list.txt` | sed 's/Chloe/$i.1; /CA/$i.2/g' $i.letter.txt >Why don't you just try it and see if it works?
On Wed, Jun 17, 2009 at 10:54 AM, chloe K<chloekcy2000 at 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 >I've never seen any shell or sed syntax that allows you to subscript a line like this. You should read up on awk, although there is no simple way to do dual file processing along these lines. (An awk script for this would need to know it has two files to process and read in the first one, then print it with replacements from the second one.) Also, if the above were to work, it would be "for i in `cat...." - the "in" is part of "for" syntax.... Man pages are really handy for this sort of thing.... HTH mhr
Hi Chloe, Please start by reading this: http://www.catb.org/~esr/faqs/smart-questions.html On Wed, Jun 17, 2009 at 13:54, chloe K<chloekcy2000 at yahoo.ca> wrote:> I have a file. list.txt (two columns)Separated by what? Tabs? Spaces? Can the fields themselves have spaces in them? Do you have many records, one per row? Please give a more informative example of the file you have...> I need to put in the letter file letter.txt eg: > > Dear: Chloe > Address: CAIs that supposed to be a template? What are you trying to achieve? Replace "Chloe" with the first field and "CA" with the second field of the list.txt file? Create one file per row of list.txt? If you ask vague questions all you will have are vague answers... HTH, Filipe
chloe K 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 > > Thank you for your help >#!/bin/sh while read NAME ADDRESS do sed -e"s/Chloe/$NAME/" -e"s/CA/$ADDRESS/" <letter.txt>$NAME.letter.txt done <list.txt Seems sort of fragile in that the name field can't have spaces. -- Les Mikesell lesmikesell at gmail.com
Hi If your file has only 2 columns and there is no space exists in 2nd column then you can use this script #!/bin/sh FILE="list.txt" OUTPUT="out.txt" while read VAL do VAL1=$(echo $VAL | awk '{print $1}' ) VAL2=$(echo $VAL | awk '{print $2}' ) echo "DEAR: $VAL1" >> $OUPUT echo "DEAR: $VAL2" >> $OUPUT echo " ">> $OUTPUT done<$FILE if you have spaces in between your 2nd column you might have to format the file using awk/sed so that there would be a valid delimeter between column1 and column2 column 1| column2 here we can use '|' as the delimeter and change awk statement to awk -F '| ' '{print $1}' or something like this. -- Regards, Mohan. chloe K 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 > > Thank you for your help > > > > > > > > ------------------------------------------------------------------------ > Looking for the perfect gift?* Give the gift of Flickr!* > <http://www.flickr.com/gift/> > ------------------------------------------------------------------------ > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20090618/39a4d690/attachment-0001.html>
From: chloe K <chloekcy2000 at yahoo.ca>> 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.txtFor single words space separated: cat list.txt | while read LINE do set $LINE printf "Dear: %s\nAddress: %s\n" $1 $2 >> $1.letter.txt done JD