mIRC Home    About    Download    Register    News    Help

Print Thread
add words to a file with erasing the rest off line #200902 14/06/08 04:15 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
is this not supose to add words to the line 1 instead erase the line and add a new text ??

Code:
write -i test.txt 1 
write -i test.txt and 2


the file appeas like this:
Code:
and 2


is there something rong with the code ?

thanks for all...

Re: add words to a file with erasing the rest off line [Re: Miguel_A] #200903 14/06/08 04:36 PM
Joined: Dec 2002
Posts: 2,010
R
RoCk Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,010

Try using the -a switch which would make it append the specified text to the existing line.

/write -l1 test.txt 1
/write -al1 test.txt and 2

Re: add words to a file with erasing the rest off [Re: RoCk] #200904 14/06/08 05:02 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
yehh liek that it works.

Thanks ?

But shouldīt it work either with only the -i option ??
Is it any bug ?

Re: add words to a file with erasing the rest off [Re: Miguel_A] #200905 14/06/08 05:35 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Code:
//write -i test.txt hi
//write -i test.txt bye
//echo -a $lines(test.txt) == 2
//echo -a $read(test.txt,n,1) == hi
//echo -a $read(test.txt,n,2) == bye


Looks fine to me. When I run the code you pasted I get both lines in the file as well. Your problem must be coming from something else in your script that you aren't including in this post. Try the code you pasted here, you'll see that it writes both lines to the file.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: add words to a file with erasing the rest off [Re: argv0] #200906 14/06/08 05:41 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
strange not on me...

i have put this

Code:
alias test {
  remove test.txt
  write -i1 test.txt hi
  write -i1 test.txt bye
  echo -a $lines(test.txt) == 2
  echo -a $read(test.txt,n,1) == hi
  echo -a $read(test.txt,n,2) == bye
}


Both in version 6.21 and version 6.32 the output is this one

Code:
-
* Removed 'mircdir\test.txt'
-
2 == 2
hi == hi
bye == bye

Last edited by Miguel_A; 14/06/08 05:46 PM.
Re: add words to a file with erasing the rest off [Re: Miguel_A] #200907 14/06/08 05:42 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
That's the correct output, which proves it works fine.. so what's the problem?


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: add words to a file with erasing the rest off [Re: argv0] #200908 14/06/08 05:46 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
it should be:

Code:
1 = 2
hi bye = hi
= bye


i want to insert text to the line not insert a new line with new text. And i have change the code to "write -i1"...

if i donīt use the -a option it will not insert text to that line, but it will insert a new line with that text.

Last edited by Miguel_A; 14/06/08 05:48 PM.
Re: add words to a file with erasing the rest off [Re: Miguel_A] #200909 14/06/08 05:51 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
No, it should not be what you posted, it should be what I described. The help file explains very explicitly how -i behaves:

Originally Posted By: mirc.hlp
The -i switch indicates that the text should be inserted at the specified line instead of overwriting it. If you do not specify any text then a blank line is inserted. If you do not specify a line number then a blank line is added to the end of the file.


You need to do what RoCk suggested to get the results you want, but the -i behaviour is fine.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: add words to a file with erasing the rest off [Re: argv0] #200910 14/06/08 05:58 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
on both versionīs off mIRC 6.21 and 6.32.


Code:
;---------------CODE--------------
alias test {
  remove test.txt
  write -i1 test.txt hi
  write -i1 test.txt bye
  echo -a $lines(test.txt) == 2
  echo -a $read(test.txt,n,1) == hi
  echo -a $read(test.txt,n,2) == bye
}
;---------------OUTPUT-------------
2 == 2
hi == hi
bye == bye


Code:
;---------------CODE--------------
alias test1 {
  remove test.txt
  write -al1 test.txt hi
  write -al1 test.txt bye
  echo -a $lines(test.txt) == 2
  echo -a $read(test.txt,n,1) == hi
  echo -a $read(test.txt,n,2) == bye
}
;---------------OUTPUT-------------
1 == 2
hibye == hi
== bye


My second question is:

On help is saying : The -i switch indicates that the text should be inserted at the specified line instead of overwriting it. If you do not specify any text then a blank line is inserted. If you do not specify a line number then a blank line is added to the end of the file.

Why the -i $+ Line donīt work to insert text to that line like itīs says on help ??

Why do we need to use the -al $+ line option ??

Re: add words to a file with erasing the rest off [Re: Miguel_A] #200912 14/06/08 06:09 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
You misunderstand what -i means.

-i inserts a new line of text. It's meant for situations where you have a file:

line1
line2
line3

and you want to insert MYLINEXYZ in between line1 and line2.. you would use /write test.txt -i2 MYLINEXYZ to get:

line1
MYLINEXYZ
line2
line3

I assume you understand "insert" to mean "modify". That is not the case. Insert in this case means insert a new line, not to mosify an existing one. -l is used to modify existing lines (which is your version of "insert"). Finally, you need -a with -l because you need it to *append* the text to the end rather than replacing the whole line.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: add words to a file with erasing the rest off [Re: argv0] #200915 14/06/08 06:15 PM
Joined: Aug 2003
Posts: 144
M
Miguel_A Offline OP
Vogon poet
OP Offline
Vogon poet
M
Joined: Aug 2003
Posts: 144
ahhhh, got it...
yes i had misunderstud the -i meaning.

Thanks for the help.