mIRC Home    About    Download    Register    News    Help

Print Thread
Adding text to a line, in a file. #80247
23/04/04 01:42 AM
23/04/04 01:42 AM
Joined: Feb 2004
Posts: 16
D
droplogic Offline OP
Pikka bird
droplogic  Offline OP
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?

Re: Adding text to a line, in a file. #80248
23/04/04 04:19 AM
23/04/04 04:19 AM
Joined: Oct 2003
Posts: 34
Canada
S
spling Offline
Ameglian cow
spling  Offline
Ameglian cow
S

Joined: Oct 2003
Posts: 34
Canada
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.
Re: Adding text to a line, in a file. #80249
23/04/04 07:07 AM
23/04/04 07:07 AM
Joined: Aug 2003
Posts: 1,831
I
Iori Offline
Hoopy frood
Iori  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
}

Re: Adding text to a line, in a file. #80250
23/04/04 03:58 PM
23/04/04 03:58 PM
Joined: Aug 2003
Posts: 325
W
Wolfie Offline
Fjord artisan
Wolfie  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