Merge 2 text file  
Author Message
espirit





PostPosted: Visual FoxPro General, Merge 2 text file Top

Hi...

I have to text file. Can anyone advise how to combine 2 text file into one file using Visual Foxpro 6.0. Thank you.



Visual FoxPro2  
 
 
Markish





PostPosted: Visual FoxPro General, Merge 2 text file Top

Hi,
You can simply try with

run copy file1.txt+file2.txt
this will append the file2.txt to file1.txt

otherwise you can try with
create a table

appe from file1.txt sdf
appe from file2.txt sdf

then you can export the file to a text file...

Regards,
Markish



 
 
espirit





PostPosted: Visual FoxPro General, Merge 2 text file Top

Hi Markish,

Sorry maybe I didn't make it clear just now. Actually what I wanted to do is as following:-

I have one file call product.dbf another file call destination.txt

Product.txt

product id description product group

A01 ball pen pen

Destination.txt

destination id name

P01 penang

I want the output to be like this:-

product id description product group destination

A01 ball pen pen penang

Kindly advise. Thank you.


 
 
Lakshminarayana





PostPosted: Visual FoxPro General, Merge 2 text file Top

if u know the layout of destination.txt, you can create a blank structrue and say

  1. use destination
  2. appe from desitnation.txt sdf

or u can open destination.txt in excel and save it as dbf.

then u can match product and destination to get a 3rd file

i.e.

sele a.productid,a.description,a.productgroup,b.destination from product a,destination b where a.productid = b.productid into dbf prddest.dbf

your prddest.dbf will have all product codes with destination,description and group



 
 
Markish





PostPosted: Visual FoxPro General, Merge 2 text file Top

Hi,
sorry, probably I's mistaken....I've not tried. The following code may work

mdbf1=getf('DBF')
mdbf2=getf('DBF')
sele a
use &mdbf1
copy struc to temp1 exten
sele b
use &mdbf2
copy struc to temp2 exten
sele c
use temp1
appen from temp2
crea dest from temp1
use dest
stor .t. to mex_a,mex_b
do while mex_a or mex_b
scatter name otemp blank
if mex_a
sele a
scatter name otemp
skip
if eof()
mex_a=.f.
endif
endif
if mex_b
sele b
scatter name otemp ****ive
skip
if eof()
mex_b=.f.
endif
endif
sele dest
appen blan
gather name otemp
enddo
clos data
return

Please Note this works when both table have no field name in common for which you may need to modify little

Regards,

Markish



 
 
CetinBasoz





PostPosted: Visual FoxPro General, Merge 2 text file Top

You're not really combining 2 txt files but 2 sets of data. If you were combining 2 text files then it'd be as simple as:

strtofile(filetostr('destination.txt'),'product.txt',.t.)

This appends destination.txt content to product.txt.

You could get the data into cursors and then join and write them back to a 'merged' text file. However there is no relation in your data sample for a join so I don't know what is the logic behind making "penang" as destination for product A01. If you mean it's simply a line to line match:

 

lcProductTemplate = "product id                  description                 product group"
lcDestinationTemplate = "destination id            name"
lcMergedTemplate  = "product id                  description                 product group               destination"
Create cursor crsProduct ;
    (productID c( atc('Description',m.lcProductTemplate)-1 ), ;
    description c( atc('Product Group',m.lcProductTemplate) - atc('Description',m.lcProductTemplate) ), ;
    productGrp c( atc('Destination',m.lcMergedTemplate) - atc('Product Group',m.lcMergedTemplate) ) )
Append from ('product.txt') type SDF for !empty(productID) and lower(productID) != "product id"
Create cursor crsDestination ;
    ( destinationID c( atc('Name', m.lcDestinationTemplate)-1 ),name c(254))
Append from ('destination.txt') type SDF for !empty(destinationID) and lower(destinationID) != "destination id"
Select crsProduct
Set relation to recno() into crsDestination
Set textmerge to merged.txt noshow
Set textmerge on
\\<<m.lcMergedTemplate>>
Scan
\<<productID>>
\\<<padr(ltrim(Description),len(Description))>>
\\<<padr(ltrim(ProductGrp),len(ProductGrp))>>
\\<<ltrim(crsDestination.name)>>
Endscan
Set textmerge to
Set textmerge off