mIRC Homepage
Posted By: TC_Tomcat Formatting a file - 29/12/02 03:27 PM
I am trying to write a script that will read a txt file line by line, removing a specified amount of spaces to the right of the start of the line. Now I am unsure if I am using the right identifiers but....would make an alias

alias altered {
set %i 1
write $2 $right($read($1 ,s, * , %i )6))
inc %i
}

usage would be
/altered one.txt two.txt

I know I am also missing a loop to cycle through each line of the file til it's done but I am unsure of how to put that in either...I know it's asking a lot but if I can get some guidance I would appreciate it very much...

TIA
TC
Posted By: Saturne Re: Formatting a file - 29/12/02 03:30 PM
I would help, but I'm not sure I understood what you're up to... you want to check a txt file (one.txt) line by line, then on each line find the spaces and remove them... but what are you doing with two.txt ? reporting the line without the space in order to save the first file ? confused
Posted By: Collective Re: Formatting a file - 29/12/02 03:32 PM
"removing a specified amount of spaces to the right of the start of the line."

So the first text file would look like this:
    Text

And the second file would look like this:
Text

Is that the idea?
Posted By: TC_Tomcat Re: Formatting a file - 29/12/02 03:35 PM
ok...for example a file which may have lines that look like:

This is wasted words | ftp://127.0.0.1/

I want to remove the "This is wasted words |" and save only
ftp://127.0.0.1/ to the second file. The file has multiple lines but is consistant in the beginning...by this I mean the whole file will start on each line with "This is wasted words |".

Hope that helps more
Posted By: Dana Re: Formatting a file - 29/12/02 03:39 PM
You can find a good tutorial for writing loops here and here.

As for what you want to do, mIRC has some trouble reading a series of spaces, so I'm not quite sure just how well, this would work. However, if you're talking about reading a certain number of characters from each line only and removing all the other characters on that line, you can use this:

Code:
alias altered {
  if ($exists($2) != $true) { return }
  var %i = 0
  while (%i <= $lines($2)) {
    write $+(-l,%i) $2 $left($read($2,%i),-N)
    inc %i
  }
}

Replace N (in $left($read($2,%i),-N)) with the number of spaces that you wish to remove.
Posted By: Dana Re: Formatting a file - 29/12/02 03:42 PM
With my previous example, you'd use $right(string,-N) to accomplish this (instead of $left) where N is the number of characters in "this is wasted words".

Dana
Posted By: TC_Tomcat Re: Formatting a file - 29/12/02 04:05 PM
thank you very much....for the links as well...

cool

TC
© mIRC Discussion Forums