![]() |
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 |
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 |
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.
|
Quote:
|
upload the following and your file to be converted as filename.txt:
Code:
$contents = file_get_contents("filename.txt"); alternatively if you have ssh access, you could do: Code:
awk < filename.txt -F\| '{ print $2 "|" $1 "|" $3 }' > outfile.txt |
Thank you CD
i put that code in my the top of my txt file ?? |
Quote:
|
wow... i just did... CD 34 I fucking Love you !!!
thank you Bob !! |
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 |
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. |
Quote:
Or you could output it all to a new txt file by making a few modifcations PHP Code:
|
You could always use Excel and cut/paste columns.
|
Thanks Bob and CD, I'll be working on this over the weekend Ill post my results LOL wish me luck. haha
|
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 |
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... |
Quote:
PHP Code:
|
Quote:
|
Code:
if (trim($line) != "") { |
Thanks Bob - perfect :)
|
Quote:
theres usually millions of ways you can accompilsh the same thing with programming. |
Quote:
|
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 |
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. |
Quote:
|
This is really helpful ! Thanks guys ;)
|
All times are GMT -4. The time now is 12:14 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc