Jump to content

Someone Please help me write a rather simple script!


phatzilla
 Share

Recommended Posts

Edit: Thanks figured out first problem

Second problem: (Two pronged issue)

Is there anyway to add 'extra' data to a txt file.

So if i download 10x txt files from a URL, can i have ALL that text saved in ONE txt file?

So file #1 downloaded into Text1.TXT

file #2 downloaded and ADDED to text1.txt

So that after i download ALL 10 text files, i will only have 1 text file but with all the text from the 10 files i downloaded.

Second issue: i need to search through thousands of lines of text and take 'snippets' of that text and copy it over to a frest txt file.

Example:

BlahBlahBlahBlahHELLOYadaYadaYada

BlahBlahBlahBlahWorldYadaYadaYada

BlahBlahBlahBlahImYadaYadaYada

BlahBlahBlahBlahPhatzillaYadaYadaYada

So what im saying is that im trying to copy the following into my new text file

"Hello"

"World"

"im"

"Phatzilla"

(all as individual lines).

I KNOW that BlahBlahBlahBlah Precedes The word I want to copy and that YadaYadaYada Succeeds the word every single time.

So how can i write a script that extracts the word(or should i say string) from between blahblahblah and yadayadayada? Theres thousands of these 'words' and i obviously dont know what they are, but i do know that what precedes and succeeds them is always constant.

Edited by phatzilla
Link to comment
Share on other sites

Link to comment
Share on other sites

Please stop editing your problem posts. Add to them don't redo them. Leave your initial problems intact so that people who search the forum can gain the help as well. As for reading certain things try reading the file contents with FileReadLine() and look at StringInStr().

Link to comment
Share on other sites

totally over my head.

The problem with StringInStr()

is that i dont KNOW what the substring is.

I know what string precedes and suceeds it. But i dont know WHAT the string is that im looking for. as in i dont know that its "phatzilla" in the first example.

The string in question also varies in character length, so i cant use like StringLeft or StringRight

Edited by phatzilla
Link to comment
Share on other sites

  • Moderators

FileWrite("filename.log", "text downloaded" & @CRLF) to append the text to the file already in question.

#include <array.au3>
Local $a_sre = StringRegExp(FileRead("filename.log"), "(?i)BlahBlahBlahBlah(.+?)YadaYadaYada", 3)
_ArrayDisplay($a_sre)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I don't see how.

$File = FileOpen("filename",2)
$FileOut = FileOpen("output name",10)

For $i = 1 To FileCountLines($File)
$line = FileReadLine($File,$i)
If StringInStr($line,"stuff before") = 1 And StringInStr($line,"stuff after") = 1 Then
$lineout = StringReplace(StringReplace($line,"stuf fbefore",""),"stuff after","")
FileWrite($FileOut,$lineout)
Next
This is an example but may work when you replace the proper things and dim the variables I used. Also I'm not sure if the syntax for everything is perfect (I don't have autoit on this comp to check) so it wouldn't hurt to double check things with the helpfile before you run it, it fails, and you complain. :)

Edit: crud Sm0ke_N beat me to it, and his solution will probably work better XD

Edited by dbzfanatic
Link to comment
Share on other sites

Thanks smoke, that helped! I tried your array thing and it worked perfectly, however i only need the data from array #39 through #138. Everything else is useless to me. I'd like to take the strings stored in the aforementioned arrays and append them to a TXT file. How would i go about doing that?

Edited by phatzilla
Link to comment
Share on other sites

For $i = 39 To 138
FileWrite($output_file,$a_sre[$i])
Next

Something like that should work. Also make sure that the output file was oppened with mode 2 to append the text and not overwrite it.

Edited by dbzfanatic
Link to comment
Share on other sites

You're welcome, glad to help. If all of your problems are fixed please put [sOLVED] in your title so people know that you have what you need and others who are searching can see that this has a solution they may be able to use.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...