Greenguy's Board WebcamWiz CRAZY $5,000 Reward Bonuses


Go Back   Greenguy's Board > General Business Knowledge
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2009-02-13, 11:21 AM   #1
Tommy
NYC Boy That Moved To The Island
 
Join Date: Apr 2003
Posts: 2,940
Send a message via ICQ to Tommy
Does Anyone know how to rearrage a text file

Like for instance you have


URL|TITLE|DECRIPTION

I wanna rearrange it so its
TITLE|URL|DECRIPTION
__________________
Accepting New partners
Tommy is offline   Reply With Quote
Old 2009-02-13, 11:51 AM   #2
NY Jester
ICQ:147*079*406
 
NY Jester's Avatar
 
Join Date: Oct 2007
Location: Rock*ME*Hardplace
Posts: 2,996
Send a message via ICQ to NY Jester Send a message via AIM to NY Jester
Tommy, Im experiencing the same thing, so I'd be interested in the answer to this as well.

I have it with just two variables TITLE|URL and need it reversed to URL|TITLE and a simple find / replace will not work
__________________
The Sexy Side of Porn
NY Jester is offline   Reply With Quote
Old 2009-02-13, 12:04 PM   #3
Beaver Bob
Porn Blog Addict
 
Beaver Bob's Avatar
 
Join Date: Oct 2005
Location: Las Vegas, Nevada
Posts: 715
Send a message via ICQ to Beaver Bob
You could do it with a small script. Open the contents of the file and put it into a variable. explode() into an array for each carriage return.. and then for each element in that array, explode() on the pipe symbol, and then just rewrite the data to a new file.
Beaver Bob is offline   Reply With Quote
Old 2009-02-13, 12:15 PM   #4
bDok
bang bang
 
bDok's Avatar
 
Join Date: Mar 2005
Location: SD/OC/LA
Posts: 3,241
Send a message via ICQ to bDok
Quote:
Originally Posted by Beaver Bob View Post
You could do it with a small script. Open the contents of the file and put it into a variable. explode() into an array for each carriage return.. and then for each element in that array, explode() on the pipe symbol, and then just rewrite the data to a new file.
exactly... I have to run right now to get the car serviced. If nobody has done the code by the time I get back I'll write something real quick.
__________________
submit to Nymphotic
submit to Moistlace
bDok is offline   Reply With Quote
Old 2009-02-13, 12:35 PM   #5
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
upload the following and your file to be converted as filename.txt:

Code:
<?php
  $contents = file_get_contents("filename.txt");
  $line_by_line = explode("\n", $contents);
  array_pop($line_by_line); // get rid of the empty line at the end that explode creates
  $results = array();

  foreach ($line_by_line as $line) {
    list ($url, $title, $description) = explode("|", $line);
    print "$title|$url|$description\n";
  }
?>
The php version will output the result from your screen so that you can cut and paste it into whatever.

alternatively if you have ssh access, you could do:

Code:
awk < filename.txt -F\| '{ print $2 "|" $1 "|" $3 }' > outfile.txt
and end up with the result in outfile.txt which could be downloaded.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2009-02-13, 01:01 PM   #6
Tommy
NYC Boy That Moved To The Island
 
Join Date: Apr 2003
Posts: 2,940
Send a message via ICQ to Tommy
Thank you CD

i put that code in my the top of my txt file ??
__________________
Accepting New partners
Tommy is offline   Reply With Quote
Old 2009-02-13, 01:08 PM   #7
Beaver Bob
Porn Blog Addict
 
Beaver Bob's Avatar
 
Join Date: Oct 2005
Location: Las Vegas, Nevada
Posts: 715
Send a message via ICQ to Beaver Bob
Quote:
Originally Posted by Tommy View Post
Thank you CD

i put that code in my the top of my txt file ??
no, you rename your text file to filename.txt and upload what CD wrote into a seperate php file. upload them both to the same folder and run the php file.
Beaver Bob is offline   Reply With Quote
Old 2009-02-13, 01:11 PM   #8
Tommy
NYC Boy That Moved To The Island
 
Join Date: Apr 2003
Posts: 2,940
Send a message via ICQ to Tommy
wow... i just did... CD 34 I fucking Love you !!!

thank you Bob !!
__________________
Accepting New partners
Tommy is offline   Reply With Quote
Old 2009-02-13, 01:20 PM   #9
Simon
That which does not kill us, will try, try again.
 
Simon's Avatar
 
Join Date: Aug 2003
Location: Conch Republic
Posts: 5,150
Send a message via ICQ to Simon Send a message via AIM to Simon Send a message via Yahoo to Simon
Tommy -- also, if you use a text editor with 'Grep' search and replace capabilities you can do it easily.

search string would be:

(.*)\|(.*)\|(.*)\r

Replace with:

\2|\1|\3\r

and 'replace all'


BBEdit on the Mac has had that kind of search built in for years.
Not sure what the comparable Windows text editor would be, but the search and replace string would be the same in any editor that can do regex (regular expression) searching.

HTH
__________________
"If you're happy and you know it, think again." -- Guru Pitka
Simon is offline   Reply With Quote
Old 2009-02-13, 01:29 PM   #10
NY Jester
ICQ:147*079*406
 
NY Jester's Avatar
 
Join Date: Oct 2007
Location: Rock*ME*Hardplace
Posts: 2,996
Send a message via ICQ to NY Jester Send a message via AIM to NY Jester
Kind of new at the php thng, so if create the file rearrange .php using the code above along with the txt file that has the lines I want to change then just access rearrange. php and it will out put on the screen the rearrange strings?

Thanks in advance.
__________________
The Sexy Side of Porn
NY Jester is offline   Reply With Quote
Old 2009-02-13, 02:40 PM   #11
Beaver Bob
Porn Blog Addict
 
Beaver Bob's Avatar
 
Join Date: Oct 2005
Location: Las Vegas, Nevada
Posts: 715
Send a message via ICQ to Beaver Bob
Quote:
Originally Posted by NY Jester View Post
Kind of new at the php thng, so if create the file rearrange .php using the code above along with the txt file that has the lines I want to change then just access rearrange. php and it will out put on the screen the rearrange strings?

Thanks in advance.
Yes.

Or you could output it all to a new txt file by making a few modifcations
PHP Code:
<?php
  $contents 
file_get_contents("filename.txt");
  
$line_by_line explode("\n"$contents);
  
array_pop($line_by_line); // get rid of the empty line at the end that explode creates
  
$results = array();

  
$new_contents '';
  foreach (
$line_by_line as $line) {
    list (
$url$title$description) = explode("|"$line);
    
$new_contents .= "$title|$url|$description\n";
  }

  
$file fopen("new-filename.txt");
  
fwrite($file$new_contents);
  
fclose($file);
?>
Beaver Bob is offline   Reply With Quote
Old 2009-02-13, 02:59 PM   #12
tickler
If there is nobody out there, that's a lot of real estate going to waste!
 
tickler's Avatar
 
Join Date: Dec 2003
Posts: 2,177
You could always use Excel and cut/paste columns.
__________________
Latina Twins, Solo, NN, Hardcore
Latin Teen Cash
tickler is offline   Reply With Quote
Old 2009-02-13, 03:42 PM   #13
NY Jester
ICQ:147*079*406
 
NY Jester's Avatar
 
Join Date: Oct 2007
Location: Rock*ME*Hardplace
Posts: 2,996
Send a message via ICQ to NY Jester Send a message via AIM to NY Jester
Thanks Bob and CD, I'll be working on this over the weekend Ill post my results LOL wish me luck. haha
__________________
The Sexy Side of Porn
NY Jester is offline   Reply With Quote
Old 2009-02-13, 05:06 PM   #14
plateman
What can I do - I was born this way LOL
 
plateman's Avatar
 
Join Date: Oct 2003
Location: ohio
Posts: 3,086
off topic here but text magician can save a bunch of time when making text files for importing galls into tgp scripts

like adding custom stuff that a lot of sponsor text file tools won't add
__________________
Submit to: Porn O Plenty XXX Links
Reality Here
plateman is offline   Reply With Quote
Old 2009-02-13, 08:29 PM   #15
dunc
You can now put whatever you want in this space :)
 
dunc's Avatar
 
Join Date: Feb 2007
Location: Australia
Posts: 658
Sort of related - I have a bunch of stories which I want to use - but all the lines are double spaced

Is there a way of clearing all empty lines using php...
dunc is offline   Reply With Quote
Old 2009-02-13, 08:38 PM   #16
Beaver Bob
Porn Blog Addict
 
Beaver Bob's Avatar
 
Join Date: Oct 2005
Location: Las Vegas, Nevada
Posts: 715
Send a message via ICQ to Beaver Bob
Quote:
Originally Posted by dunc View Post
Sort of related - I have a bunch of stories which I want to use - but all the lines are double spaced

Is there a way of clearing all empty lines using php...
try this

PHP Code:
<?php
  $contents 
file_get_contents("filename.txt");
  
$line_by_line explode("\n"$contents);
  
array_pop($line_by_line); // get rid of the empty line at the end that explode creates
  
$results = array();

 
$counter 0;
  foreach (
$line_by_line as $line) {
    if(
$counter == 0) {
       print 
"$line\n";
    }
    
$counter++;
  }

?>
Beaver Bob is offline   Reply With Quote
Old 2009-02-13, 10:13 PM   #17
MeatPounder
Women might be able to fake orgasms But men can fake whole relationships
 
MeatPounder's Avatar
 
Join Date: Oct 2003
Location: Fort Lauderdale, Fl
Posts: 2,408
Quote:
Originally Posted by Simon View Post
Tommy -- also, if you use a text editor with 'Grep' search and replace capabilities you can do it easily.

search string would be:

(.*)\|(.*)\|(.*)\r

Replace with:

\2|\1|\3\r

and 'replace all'


BBEdit on the Mac has had that kind of search built in for years.
Not sure what the comparable Windows text editor would be, but the search and replace string would be the same in any editor that can do regex (regular expression) searching.

HTH
Find and replace all in notepad?
MeatPounder is offline   Reply With Quote
Old 2009-02-13, 10:14 PM   #18
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
Code:
if (trim($line) != "") {
// rest of stuff
}
would eliminate blank lines assuming that the file MIGHT not have every other line as blank.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2009-02-13, 10:30 PM   #19
dunc
You can now put whatever you want in this space :)
 
dunc's Avatar
 
Join Date: Feb 2007
Location: Australia
Posts: 658
Thanks Bob - perfect
dunc is offline   Reply With Quote
Old 2009-02-13, 10:33 PM   #20
Beaver Bob
Porn Blog Addict
 
Beaver Bob's Avatar
 
Join Date: Oct 2005
Location: Las Vegas, Nevada
Posts: 715
Send a message via ICQ to Beaver Bob
Quote:
Originally Posted by dunc View Post
Thanks Bob - perfect
actually cd34's is the better way, mine was going under the assumption that every other line was blank.. his checks if the line is blank or not.

theres usually millions of ways you can accompilsh the same thing with programming.
Beaver Bob is offline   Reply With Quote
Old 2009-02-13, 11:31 PM   #21
Mr Spock
You can now put whatever you want in this space :)
 
Mr Spock's Avatar
 
Join Date: Nov 2006
Location: Vulcan
Posts: 695
Quote:
Originally Posted by tickler View Post
You could always use Excel and cut/paste columns.
Easiest way , especially if you are not a code head
Mr Spock is offline   Reply With Quote
Old 2009-02-13, 11:56 PM   #22
dunc
You can now put whatever you want in this space :)
 
dunc's Avatar
 
Join Date: Feb 2007
Location: Australia
Posts: 658
Well even more thanks to cd34 (I didn't even see that you posted before my reply )

I don't seem to be getting thread reply notifications anymore - I'll check my options
dunc is offline   Reply With Quote
Old 2009-02-14, 06:21 AM   #23
Simon
That which does not kill us, will try, try again.
 
Simon's Avatar
 
Join Date: Aug 2003
Location: Conch Republic
Posts: 5,150
Send a message via ICQ to Simon Send a message via AIM to Simon Send a message via Yahoo to Simon
Quote:
Sort of related - I have a bunch of stories which I want to use - but all the lines are double spaced
Is there a way of clearing all empty lines using php...
As an alternative, using regex in a text editor you can do this...

Search for: \r\r
Replace with: \r

Finds two carriage returns in a row and replaces them with one carriage return.

If I'm searching for *nix line feeds instead of carriage returns, I use \n instead of \r in the search and replace.

Again, I'm not sure which Windows editors do these kinds of searches, but BBEdit on the Mac lets you run these kinds of searches on a whole folder full of text files and process them as a batch right from the text editor.

If you don't need to preserve the order of the lines, one other option would be to sort the text file, which would put all the blank lines together so you can delete them. Then cleaned text file could be opened in Excel or other spreadsheet program where the lines can be sorted randomly again if you need to do that before importing to somewhere.
__________________
"If you're happy and you know it, think again." -- Guru Pitka

Last edited by Simon; 2009-02-14 at 06:28 AM..
Simon is offline   Reply With Quote
Old 2009-02-14, 09:50 AM   #24
secretagentwilly
You can now put whatever you want in this space :)
 
secretagentwilly's Avatar
 
Join Date: Sep 2005
Location: Los Angeles, California
Posts: 637
Quote:
Originally Posted by Mr Spock View Post
Easiest way , especially if you are not a code head
I use excel for this...If I have a url|title|description and I need them rearranged, I first paste in a text editor like textpad or dreamweaver and do a find & replace for | with a tab. Doing this will make it so there's enough space between each variable that excel will put each in it's own column...that's just my way...but this php stuff looks great...complicated, but great...
secretagentwilly is offline   Reply With Quote
Old 2009-02-14, 10:16 AM   #25
JackDaniel's
I like work, it fascinates me, I can sit and look at it for hours...
 
JackDaniel's's Avatar
 
Join Date: Dec 2006
Posts: 3,217
Send a message via ICQ to JackDaniel's
This is really helpful ! Thanks guys
__________________
Submit Your Sites : Get Porn Links
JackDaniel's is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:51 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc