mIRC Home    About    Download    Register    News    Help

Print Thread
#181850 01/08/07 01:40 AM
Joined: Jul 2004
Posts: 59
L
Babel fish
OP Offline
Babel fish
L
Joined: Jul 2004
Posts: 59
Im looking for a way to remove a duplicate # from A text File Line. And am kinda stuck on where to start I thaught /filter but am lost.

here is an example of the file

1:1 1:1 The Command Structure for the .....
1:2 1:2 Issue A clearance for one or more .....
1:3 1:3 .......
2:1 2:1 Next Section


I would like to remove either the 1st or second instance from the complete file Aprox 1000+ lines.

Any help would be welcomed

Joined: Jul 2006
Posts: 107
L
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
/filter is great, but i don't think it will help you here. I'd try $deltok

/help token identifiers

Code:
alias cleanup {
  window -h @temp
  var %c = $lines(filename.txt), %x = 1, %L
  while ( %x <= %c ) {
    %L = $read(filename.txt,nt,%x)
    if ( $gettok(%L,1,32) == $gettok(%L,2,32) ) && ( $left($v1,1) isnum ) {
      aline @temp $deltok(%L,1,32)
    }
    else aline @temp %L
    inc %x
  }
  savebuf %c @temp file_EDIT.txt
  window -c @temp
  echo 4 -s Done editing.
}

Replace filename.txt, use the full path to your file if it is not in main mirc directory
AND
replace file_EDIT.txt

Note that savebuf will overwrite with no notice, so you really really should use a different name for the resulting file.
I'm too tired to think of better error checking.

Last edited by LonDart; 01/08/07 10:36 AM.

LonDart
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Originally Posted By: LittleJohn
Im looking for a way to remove a duplicate # from A text File Line. And am kinda stuck on where to start I thaught /filter but am lost.

here is an example of the file

1:1 1:1 The Command Structure for the .....
1:2 1:2 Issue A clearance for one or more .....
1:3 1:3 .......
2:1 2:1 Next Section


I would like to remove either the 1st or second instance from the complete file Aprox 1000+ lines.

Any help would be welcomed


Code:
alias remdup {
  var %x = 1
  if (!$1) { echo -a 4,1Error! Syntax: /remdup path/filename.txt | return }
  else {
    while (%x <= $lines($1)) {
      write $+(-l,%x) $1 $deltok($read($1,%x),2,32)
      inc %x
    }
  }
}


This code will work as you use it /remdup filename.txt will edit your current file that you call and remove the second instant as long its like that all over the file.

1:1 1:1 The Command Structure for the .....
1:2 1:2 Issue A clearance for one or more .....
1:3 1:3 .......
2:1 2:1 Next Section

will become

1:1 The Command Structure for the .....
1:2 Issue A clearance for one or more .....
1:3 .......
2:1 Next Section

you can also setup another var for sfile and use sfile to have the ability to select a file but this will do for now


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Aug 2005
Posts: 525
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Code:
alias undupe {
  .fopen -no tmp unduped.txt
  filter -fk $qt($1) undupe_wf *
  .fclose tmp
}

alias -l undupe_wf .fwrite -n tmp $token($1-,2-,32)


Code goes in remotes (alt + r)

Useage: /undupe <filename>

After execution, a "clean" version of the file will be stored in unduped.txt inside your mIRC directory.

As per the previous solution given, the format of the lines is assumed to be consistent throughout the file, else this won't work as expected. This is also much faster than the previous solutions, especially on files with a large number of lines (thousands).


Link Copied to Clipboard