GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   program to merge 2 txt-files needed (https://gfy.com/showthread.php?t=96922)

Nat 12-31-2002 12:27 AM

program to merge 2 txt-files needed
 
I would need a simple program/script that can merge 2 txt-files into one. The way it should be done is that the first line from txt1.txt should be written into txt3.txt, then the first line from txt2.txt should be written at the end of the first line in txt3.txt, then the second line from txt1.txt and second line of txt2.txt should appear on line 2 in txt3.txt etc.

so when viewing txt3.txt it would look just like if i have created 2 tables on a webpage listing txt1.txt in the first one and txt2.txt in the second.

Am i making any sense? if so, please help me out if anyone have something to do this, Thanks!

pornJester 12-31-2002 12:29 AM

should be simple with a few unix commands, i forget what they are though ;(

Living For Today 12-31-2002 12:30 AM

unix is simple. but you have to be a genius to understand its simplicity.

Nat 12-31-2002 12:35 AM

I will be more than happy for the time being if i just know how to merge a couple of files in the way described :)

pornJester 12-31-2002 12:37 AM

ok, i remember now...

cat file1 file2 > file3

from a unix command line

MonkeyMan 12-31-2002 12:40 AM

well heres a simple little php script that would do it....
Echo it to the screen then just save as .TXT

PHP Code:

<?php 

$length 
= (APPROX FILE LENGTH)
$fa file("file1.txt");
$fb file("file2.txt");
for(
$x=0$x<$length$x++)
{
echo 
$fa[$x] . $fb[$x] ."\n";
}

?>


p1mpdogg 12-31-2002 12:41 AM

for i in $(ls file*)
do
cat $i >> nameofnewfile
done <enter>

then the compiled file will be nameofnewfile

Nat 12-31-2002 12:41 AM

pornJester: nah, that will only add the files after eachother..

MonkeyMan: great! thx!

MonkeyMan 12-31-2002 12:43 AM

Nat please recopy the code or replace $START with the number 0
I forgot to do that.

pornJester 12-31-2002 12:46 AM

Quote:

Originally posted by Nat
pornJester: nah, that will only add the files after eachother..

MonkeyMan: great! thx!

ya, i had just breezed over what you typed and thought that's what you were looking for, now that i read it more carefully i see what you were trying to do. It's late, need sleep ;)

Nat 12-31-2002 12:48 AM

MonkeyMan: em, help? :)

Parse error: parse error in /home/html/index.php on line 5

Nat 12-31-2002 01:01 AM

Quote:

Originally posted by p1mpdogg
for i in $(ls file*)
do
cat $i >> nameofnewfile
done <enter>

then the compiled file will be nameofnewfile

Yeah, but that will only add txt2.txt after txt1.txt, not side by side as i'm looking for...

p1mpdogg 12-31-2002 01:03 AM

Quote:

Originally posted by Nat


Yeah, but that will only add txt2.txt after txt1.txt, not side by side as i'm looking for...

or you can rename your files you want to merge with the same prefix like

imadaddy.txt
imadaddy2.txt
imadaddy3.txt
then do
im*

Nat 12-31-2002 01:08 AM

im*? what command are you reffering to?

p1mpdogg 12-31-2002 01:10 AM

for i in $(ls im*)
do
cat $i >> nameofnewfile
done


this will combine all files that start with im into the 'nameofnewfile'

MonkeyMan 12-31-2002 01:16 AM

Quote:

Originally posted by Nat
MonkeyMan: em, help? :)

Parse error: parse error in /home/html/index.php on line 5


ooops
on this line add the ;

$length = 1000;


and make shre you replace "(APPROX FILE LENGTH)"
with a number


you should have

PHP Code:

<?php 
$length 
1000;
$fa file("file1.txt");
$fb file("file2.txt");
for(
$x=0$x<$length$x++)
{
echo 
$fa[$x] . $fb[$x] ."\n";
}
?>

but if the files are longer than 1000 lines increase that number.

Nat 12-31-2002 01:17 AM

yes, but it will just add txt2.txt to the end of txt1.txt, but i want them to be added on the same line, line for line... reread my first post for a better explanation...

Nat 12-31-2002 01:23 AM

Great! got it working...
thanks!


All times are GMT -7. The time now is 07:12 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123