mIRC Home    About    Download    Register    News    Help

Print Thread
txt2txt #137226
10/12/05 01:55 PM
10/12/05 01:55 PM
Joined: Mar 2005
Posts: 39
B
bapplander Offline OP
Ameglian cow
bapplander  Offline OP
Ameglian cow
B

Joined: Mar 2005
Posts: 39
Hello, I have a textfile.txt with data stored as
data1 data2 data3

I would like to change this into newtxtfile.txt, stored as
data2 data1

Is it any small easy way to make a code todo this?

Re: txt2txt #137227
10/12/05 02:44 PM
10/12/05 02:44 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
DaveC  Offline
Hoopy frood
D

Joined: Sep 2003
Posts: 4,230
mirc 6.16 only
type at the prompt the following 4 lines

/alias davec { tokenize 32 $1 | write newtxtfile.txt $2 $1 }
/remove newtxtfile.txt
/filter -fk textfile.txt davec
/alias davec

you can actualy just copy them from here and use SHIFT-INSERT to paste them in and all 4 should run.

Re: txt2txt #137228
10/12/05 02:52 PM
10/12/05 02:52 PM
Joined: Apr 2003
Posts: 701
Leuven, Belgium
K
Kelder Offline
Hoopy frood
Kelder  Offline
Hoopy frood
K

Joined: Apr 2003
Posts: 701
Leuven, Belgium
Here's one script, just realize there are many possibilities to do this, each with it's own pro's and cons, especially for performance...

Code:
alias newfile {
  ; if the path or file has spaces, put " " around them
  var %oldfile = test.txt
  var %newfile = newtxtfile.txt
  .fopen old %oldfile
  if ($ferr) { echo %oldfile error | .fclose old | return }
  .fopen -n new %newfile
  if ($ferr) { echo %newfile error | .fclose new | return }
  while ((!$ferr) && ($fread(old))) {
    .fwrite -n new $gettok($v1,2,32) $gettok($v1,1,32)
  }
  .fclose new
  .fclose old
  echo done
  return
  :error
  echo error
  if ($fopen(new)) .fclose new
  if ($fopen(old)) .fclose old
}

Re: txt2txt #137229
10/12/05 02:55 PM
10/12/05 02:55 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
DaveC  Offline
Hoopy frood
D

Joined: Sep 2003
Posts: 4,230
nice code, i had assumed this was a one off thing he needed doing so just gave him some commands he could type. I guess we covered it either way now.