mIRC Home    About    Download    Register    News    Help

Topic Options
#80247 - 23/04/04 02:42 AM Adding text to a line, in a file.
droplogic Offline
Pikka bird

Registered: 14/02/04
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..
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?

#80248 - 23/04/04 05:19 AM Re: Adding text to a line, in a file.
spling Offline
Ameglian cow

Registered: 26/10/03
Posts: 34
Loc: Canada
oh oh oh! I think I can actuially help someone *goes to make a script*
 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

Edited by spling (23/04/04 05:24 AM)

#80249 - 23/04/04 08:07 AM Re: Adding text to a line, in a file.
Iori Offline
Hoopy frood

Registered: 30/08/03
Posts: 1831
Using the File Handling commands is much faster. see /help /fopen
;  /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

#80250 - 23/04/04 04:58 PM Re: Adding text to a line, in a file.
Wolfie Offline
Fjord artisan

Registered: 07/08/03
Posts: 325
Along with what Iori said..
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.