mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2003
Posts: 144
M
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...

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

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

Joined: Aug 2003
Posts: 144
M
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 ?

Joined: Oct 2003
Posts: 3,918
A
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"
Joined: Aug 2003
Posts: 144
M
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.
Joined: Oct 2003
Posts: 3,918
A
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"
Joined: Aug 2003
Posts: 144
M
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.
Joined: Oct 2003
Posts: 3,918
A
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"
Joined: Aug 2003
Posts: 144
M
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 ??

Joined: Oct 2003
Posts: 3,918
A
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"
Joined: Aug 2003
Posts: 144
M
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.


Link Copied to Clipboard