|
|
|
|
|
|
|
![]() |
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
![]() |
#1 |
NYC Boy That Moved To The Island
|
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 |
![]() |
![]() |
![]() |
#2 |
ICQ:147*079*406
|
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 |
![]() |
![]() |
![]() |
#3 |
Porn Blog Addict
|
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.
|
![]() |
![]() |
![]() |
#4 | |
bang bang
|
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
a.k.a. Sparky
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"; } ?> alternatively if you have ssh access, you could do: Code:
awk < filename.txt -F\| '{ print $2 "|" $1 "|" $3 }' > outfile.txt
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
![]() |
![]() |
![]() |
#6 |
NYC Boy That Moved To The Island
|
Thank you CD
i put that code in my the top of my txt file ??
__________________
Accepting New partners |
![]() |
![]() |
![]() |
#7 |
Porn Blog Addict
|
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.
|
![]() |
![]() |
![]() |
#8 |
NYC Boy That Moved To The Island
|
wow... i just did... CD 34 I fucking Love you !!!
thank you Bob !!
__________________
Accepting New partners |
![]() |
![]() |
![]() |
#9 |
That which does not kill us, will try, try again.
|
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 |
![]() |
![]() |
![]() |
#10 |
ICQ:147*079*406
|
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 |
![]() |
![]() |
![]() |
#11 | |
Porn Blog Addict
|
Quote:
Or you could output it all to a new txt file by making a few modifcations PHP Code:
|
|
![]() |
![]() |
![]() |
#12 |
If there is nobody out there, that's a lot of real estate going to waste!
Join Date: Dec 2003
Posts: 2,177
|
You could always use Excel and cut/paste columns.
|
![]() |
![]() |
![]() |
#13 |
ICQ:147*079*406
|
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 |
![]() |
![]() |
![]() |
#14 |
What can I do - I was born this way LOL
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 |
![]() |
![]() |
![]() |
#15 |
You can now put whatever you want in this space :)
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... |
![]() |
![]() |
![]() |
#16 | |
Porn Blog Addict
|
Quote:
PHP Code:
|
|
![]() |
![]() |
![]() |
#17 | |
Women might be able to fake orgasms But men can fake whole relationships
Join Date: Oct 2003
Location: Fort Lauderdale, Fl
Posts: 2,408
|
Quote:
|
|
![]() |
![]() |
![]() |
#18 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
Code:
if (trim($line) != "") { // rest of stuff }
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
![]() |
![]() |
![]() |
#19 |
You can now put whatever you want in this space :)
Join Date: Feb 2007
Location: Australia
Posts: 658
|
Thanks Bob - perfect
![]() |
![]() |
![]() |
![]() |
#20 |
Porn Blog Addict
|
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. |
![]() |
![]() |
![]() |
#21 |
You can now put whatever you want in this space :)
Join Date: Nov 2006
Location: Vulcan
Posts: 695
|
|
![]() |
![]() |
![]() |
#22 |
You can now put whatever you want in this space :)
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 ![]() |
![]() |
![]() |
![]() |
#23 | |
That which does not kill us, will try, try again.
|
Quote:
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.. |
|
![]() |
![]() |
![]() |
#24 |
You can now put whatever you want in this space :)
Join Date: Sep 2005
Location: Los Angeles, California
Posts: 637
|
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...
|
![]() |
![]() |
![]() |
#25 |
I like work, it fascinates me, I can sit and look at it for hours...
|
This is really helpful ! Thanks guys
![]() |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | Rate This Thread |
|
|