Jump to content

How to identify part of line in txt and than take entire line


 Share

Recommended Posts

I've bumped on next problem:

I have txt file with bunch of mails, and I want to write script that search for specific one and put it in other txt file.

Example:

Email1@gmail.com

Email2@gmail.com

Email3@yahoo.com

Email4@hotmail.com

Now what I want is to search if domain is @gmail and output entire mail in new file.

I have tried StringInString but I have no idea what to do with number of place where is found line starting.

I'm pretty sure this should be done with StringCompare but I seams not to be able to find anyone with similar task who have posted online about this. I would appreciate any help or idea you could have and could share with me. Thanks

Link to comment
Share on other sites

Something like that:

#include <File.au3>
$file_database = @ScriptDir & "\email_database.txt"
$file_found = @ScriptDir & "\found_email_database.txt"

Global $open_file_database = FileOpen($file_database, 1)
Global $open_file_found = FileOpen($file_found, 1)


For $i = 0 To _FileCountLines($file_database)
$line = FileReadLine($open_file_database, $i)

If StringInStr($line, "@gmail") Then
       FileWriteLine($open_file_found, $line)
EndIf
Next

!!WARNING!! I have not tested this code, but here there are all the function that you need to do what you want.

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Something like that:

#include <File.au3>
$file_database = @ScriptDir & "\email_database.txt"
$file_found = @ScriptDir & "\found_email_database.txt"

Global $open_file_database = FileOpen($file_database, 1)
Global $open_file_found = FileOpen($file_found, 1)


For $i = 0 To _FileCountLines($file_database)
$line = FileReadLine($open_file_database, $i)

If StringInStr($line, "@gmail") Then
FileWriteLine($open_file_found, $line)
EndIf
Next

!!WARNING!! I have not tested this code, but here there are all the function that you need to do what you want.

Hi!

I've tried it and it simply does nothing. Something is not right.
Link to comment
Share on other sites

#include <File.au3>
$file_database = @ScriptDir & "\email_database.txt"

$file_found = @ScriptDir & "\found_email_database.txt"

Global $open_file_found = FileOpen($file_found, 1)
Local $found_email_number = 0

For $i = 0 To _FileCountLines($file_database)
$line = FileReadLine($file_database, $i)
If StringInStr($line, "@gmail") Then
$found_email_number += 1
FileWriteLine($open_file_found, $line)
EndIf
Next

FileClose($open_file_found)

If $found_email_number > 0 Then
MsgBox(0, "Done", "Found " & $found_email_number & " email.")
Else
MsgBox(0, "Error", "No email found.")
EndIf

Tested and working well.

Hi!

Edited by Nessie

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Glad to help you, take a look to my previous message, as i modified a little bit the code :)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

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

×
×
  • Create New...