mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
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?

Joined: Oct 2003
Posts: 34
S
Ameglian cow
Offline
Ameglian cow
S
Joined: Oct 2003
Posts: 34
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

Last edited by spling; 23/04/04 04:24 AM.
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
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
}

Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
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


Link Copied to Clipboard