mIRC Homepage
Posted By: droplogic Adding text to a line, in a file. - 23/04/04 01:42 AM
I'm having trouble thinking up a script to add a text i designate, to the beginning and end of each line, in a text file.

For example, let's say I had a text file with 100 lines of things like..
Hello
Hi
Howdy
How Ya Doin
What ya up to
..etc, how could I make it add, let's say.."whatever" to the beginning of each line, and "idontthinkso" to the end of each line?

Anyone got any idas?
Posted By: spling Re: Adding text to a line, in a file. - 23/04/04 04:19 AM
oh oh oh! I think I can actuially help someone *goes to make a script*
----------------------------------------------------
Code:
 alias /addlines {
  set %count $lines(FILENAME)
  while %count > 0 {
    write -l $+ %count FILENAME whateever $+ $read(FILENAME,%count) $+ idontthinkso
    dec %count 1
  }
}


Works for me smile
Posted By: Iori Re: Adding text to a line, in a file. - 23/04/04 07:07 AM
Using the File Handling commands is much faster. see /help /fopen
Code:
;  /addlines filename.ext
alias addlines {
  var %f = $+(",$remove($$1-,"),")
  .fopen aa %f
  .fopen -no ab @!@
  while !$feof {
    if $fread(aa) { .fwrite -n ab whatever $ifmatch idontthinkso } 
  }
  .fclose a?
  .remove %f
  .rename @!@ %f
}
Posted By: Wolfie Re: Adding text to a line, in a file. - 23/04/04 03:58 PM
Along with what Iori said..
Code:
write -l $+ %count FILENAME whateever $+ $read(FILENAME,%count) $+ idontthinkso

Not only misspelled "whatever" but when you use $+ it's not adding like the text together, it's cramping them together without spaces. They may want spaces between the words already there and the words being added.

laugh
© mIRC Discussion Forums