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)
-   -   A tool that can do this? (https://gfy.com/showthread.php?t=731467)

xxweekxx 05-08-2007 01:57 PM

A tool that can do this?
 
hey everyone,

say i have 2 files..
ONE TEXT FILE HAS THIS:


a
b
c
d
e
f
g

other FILE HAS THIS:

1
2
3
4
5
6
7

and i want to merge it, so that its

a1
b2
c3
d4
e5
f6
g7

any ideas?

CIVMatt 05-08-2007 01:59 PM

Microsoft Access

xxweekxx 05-08-2007 02:13 PM

tried it.. keep getting space inbetween

(if i use excel and put in diff columns then paste into notepad_

NemesisEnforcer 05-08-2007 02:13 PM

It can also be done in MS Excel or Lotus 1-2-3 (IBM).

Zoose 05-08-2007 02:17 PM

Assuming both files have the same number of lines..

Code:

$f1 = file( "file1" );
$f2 = file( "file2" );

$max = count( $f1_array );
$new = array();

for( $i = 0; $i = $max; $i++ ){

$new[] = $f1[$i] . $f2[$i] . "<br />\n";

}

print_r( $new );


fallenmuffin 05-08-2007 02:18 PM

PHP to the rescue

Code:

$file1 = @file("letters.txt");
$file2 = @file("numbers.txt");

for ($x=1;$x<count($file1);$x++) {
$output[] = $file1[x] . $file2[x];
}


fallenmuffin 05-08-2007 02:18 PM

My way is better ... lol

xxweekxx 05-08-2007 02:20 PM

this code will work?

Zoose 05-08-2007 02:20 PM

Quote:

Originally Posted by fallenmuffin (Post 12393736)
My way is better ... lol

Gonna recount em' each iteration? :p

Zoose 05-08-2007 02:23 PM

Quote:

Originally Posted by xxweekxx (Post 12393749)
this code will work?

Yes, just upload the code above in a .php file and the text files in the same directory and it'll spit out the values concatenated.

fallenmuffin 05-08-2007 02:25 PM

Quote:

Originally Posted by Zoose (Post 12393750)
Gonna recount em' each iteration? :p

No more so then you counting the array and writing it a variable.

themachinelavene 05-08-2007 06:13 PM

Quote:

Originally Posted by fallenmuffin (Post 12393788)
No more so then you counting the array and writing it a variable.

lol...i luv it when programmers fight :1orglaugh

Lee 05-08-2007 06:24 PM

Quote:

Originally Posted by themachinelavene (Post 12395130)
lol...i luv it when programmers fight :1orglaugh

Hah me too, the last time I even tried anything like that was as a kid on a Commodore 64, where it was poke this and goto that... I soon gave up but its fun watching the "discussions" between people that do understand it.

Webby 05-08-2007 06:30 PM

Hell.. don't even need a tool to do that. Just use a text editor (eg UltraEdit) in column mode and past the two columns into the one text file and delete all spaces.

p1mpdogg 05-08-2007 06:30 PM

fukin geeks

xxweekxx 05-09-2007 07:21 AM

Quote:

Originally Posted by Zoose (Post 12393775)
Yes, just upload the code above in a .php file and the text files in the same directory and it'll spit out the values concatenated.

doesnt work.. i just get

Array ( )

nothing else

schneemann 05-09-2007 07:31 AM

Quote:

Originally Posted by fallenmuffin (Post 12393733)
PHP to the rescue

Code:

$file1 = @file("letters.txt");
$file2 = @file("numbers.txt");

for ($x=1;$x<count($file1);$x++) {
$output[] = $file1[x] . $file2[x];
}


1. error suppression sucks.
2. Count the array items FIRST, not within your for loop

xxweekxx 05-09-2007 07:44 AM

well none of the codes posted here work.... unfortunately

sarettah 05-09-2007 10:29 AM

Using the code posted earlier as a start:

Code:

<?php
// bring each file into an array
$f1 = file( "testfile1.txt" );
$f2 = file( "testfile2.txt" );

// get len of each array
$max = count( $f1 );
$chkmax= count($f2);

// use shorter array as maximum value to avoind errors
if($chkmax<$max){$max=$chkmax;}

// create a new array.  You could also open a file to write to instead
$new = array();
$fp=fopen('testfile3.txt','w');

// do the loop properly.
for( $i = 0; $i <= $max; $i++ ){
  // build the new array properly
  $new[$i] = trim($f1[$i]) . trim($f2[$i]) . "\n";
  echo $new[$i] . '<br>';
  // if you are writing to a new file you can do it here if you wanted
  // check to make sure the file opened before writing
  if ($fp)
  {
    // write to the file
    fwrite($fp,$new[$i]);
  }
}
  // Print out the rows of the array using print_r or
  // if you are writing to a new file you could do it here if you wanted to too
  // print_r($new);
if ($fp)
{
    // make sure to close the file if you are writing one
  fclose($fp);
}

?>

Working model at http://sigamatic.com/newtest/testit.php

testfile 1 at http://sigamatic.com/newtest/testfile1.txt
testfile 2 at http://sigamatic.com/newtest/testfile2.txt

Ouptut file at http://sigamatic.com/newtest/testfile3.txt

Have fun :)

gornyhuy 05-09-2007 11:04 AM

Quote:

Originally Posted by xxweekxx (Post 12397258)
doesnt work.. i just get

Array ( )

nothing else

That code doesn't actually dump the results, it just puts them into an array.

ModelPerfect 05-09-2007 11:44 AM

Excel: Put each list in two separate columns (A, B), then in column C use the formula

=concatenate(A1,B1)

Copy/paste the formula all the way down and you're done. (you can then copy/paste into notepad without the spaces).

---

OR

---

Notepad: if you copy/paste the two columns and end up with the spaces, like you mentioned, simple find & replace all instances of " " with "" and the spaces are gone.

---

People are making this way too difficult.

royaljelly2 05-09-2007 11:48 AM

try modelperfect's advise on he concatenate...that shoudl certainly work.


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

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