mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2011
Posts: 6
C
CM_Punk Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Sep 2011
Posts: 6
i need to add text to a certain line in text file i have tried

Quote:
write -as $+ %name test.txt third


but that just overwrites whats there, i need it so it looks like

fred first/Second/third etc etc

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That should append it just fine. It won't add /'s for you; you'd have to add those in your /write, but it should not overwrite the line.

Originally Posted By: "test.txt"

test1 this is a test
test2 this is a test
test3 this is a test


Code:
//var %name = test2 | /write -as $+ %name test.txt third


Originally Posted By: "new test.txt"

test1 this is a test
test2 this is a testthird
test3 this is a test


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2011
Posts: 6
C
CM_Punk Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Sep 2011
Posts: 6
yeah that works like that but i didn't explain very good in first post.

i got 3 different variables let say

%test1 = fred, %test2 = bob and %test3 = john

i did the text to read

whateverlineis fred/bob/john

At the moment it goes
whateverlineis fred
bob
john

These variables could all be set within 30secs off each other.

hope that explained a bit better this time


Last edited by CM_Punk; 15/09/11 01:27 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You would have to either wait until all variables are set and write them all at once:

//write -as $+ %name test.txt %var1 %var2 %var3

Or else do a search on the line each time when the variables are set:

//write -as $+ %name test.txt %var1
//write -as $+ %name test.txt %var2
//write -as $+ %name test.txt %var3

You can also combine the variables into a single variable and write that single variable.

* I know I'm not including /'s with the /write commands like you are wanting, but these are just examples and you can easily add the /'s when you set up your script.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2011
Posts: 3
U
Self-satisified door
Offline
Self-satisified door
U
Joined: Sep 2011
Posts: 3
I would use something like this:
Code:
alias search_and_append {
  var %regex_text = Charlie
  var %file_search = texto.txt
  var %append_text = New Text

  var %read_text = $read(%file_search,r,%regex_text)
  if (%read_text) {
    echo -a Found at line: $readn $+ , appending to line...
    write $+(-l,$readn) %file_search $+(%read_text,$chr(9),%append_text)
  }
  else {
    echo -a Pattern not found, sorry.
  }
}

I used $chr(9) (Tab) as separator (Just because it looks fine).

And here my file texto.txt BEFORE:
Code:
Alfa	6	7
Bravo	5	5
Charlie	4	9
Delta	3	10
Echo	1	2
Foxtrot	2	4

And AFTER using the script:
Code:
Alfa	6	7
Bravo	5	5
Charlie	4	9	New Text
Delta	3	10
Echo	1	2
Foxtrot	2	4

Of course you can use $numtok for watching if all parameters are already in the line (If you don't want to add any other parameter).
You can use regex syntax for searching starts of line:
Code:
^Charlie

And if you want case-insensitive I would use:
Code:
/Charlie/i

And both (maybe what you are searching for, but using tabs as separators):
Code:
/^Charlie\t/i

Last edited by user001; 15/09/11 09:41 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Regex is useful in many ways, but a simple search like this doesn't need regex.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2011
Posts: 6
C
CM_Punk Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
C
Joined: Sep 2011
Posts: 6
Raimus2 i used your way an it works ago but is there a way to puta space inbetween the first part and the bit added.

Quote:
Example
test2 this is a testthird

Want it like
test3 this is a test third


I have tried putting $chr(32) but that dosent seem to work and when i try $chr(9) when i call from the text in a script it shows up blank

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You won't be able to start a /write with a space. You can use something like $chr(9) and then just $replace() it when you $read() the text.

Or you can search for the line and then overwrite the entire line instead of appending to it. That's less efficient, but would still work fine for what you're doing.

Example:
Code:
  var %text = $read(test.txt,snt,%name)
  write -l $readn test.txt %text third


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard