Jump to content

Get links from a .txt file


Recommended Posts

I have a text file which contains one link per line, but the links are prefixed and suffixed with some characters.

The suffixes are not a problem since they all contains exactly 20 characters. Prefixes contains different number of characters.

Example:

ghjgrjd.rar;http://www.netload.in/dateiGivoLSefgq/ghjgrjd.rar.htm;100 MB;2;31.05.2010
wrdrtv.rar;http://www.netload.in/dateixXm3I1wopv/wrdrtv.rar.htm;100 MB;2;31.05.2010

The problem is that the prefixes have different length from line to line and a script like this

$inputfile = FileOpen(@ScriptDir & "\input.txt", 0)
$outputfile = FileOpen(@ScriptDir & "\output.txt", 1)
While 1
$line = FileReadLine($inputfile)
If @error Then ExitLoop
$result = StringTrimLeft($line, 12)
If StringLen($line) = 0 Then FileWriteLine ($outputfile, "")
If StringLen($line) > 0 Then FileWriteLine ($outputfile, $result)
Wend
FileClose ($inputfile)
FileClose ($outputfile)

will not help.

Is possible to extract all links to a text file (one link per line) ?

Edited by ffdshow
Link to comment
Share on other sites

One possibility might be this:

$inputfile = FileOpen(@ScriptDir & "\input.txt", 0)
$outputfile = FileOpen(@ScriptDir & "\output.txt", 1)
Global $o
While 1
    $line = FileReadLine($inputfile)
    If @error Then ExitLoop
    $aRegEx = StringRegExp($line, ';(http:\/\/.*);.*;.*;', 1)
    If IsArray($aRegEx) Then $o &= $aRegEx[0] & @CRLF
Wend
FileWrite($outputfile, $o)
FileClose ($inputfile)
FileClose ($outputfile)

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 3 weeks later...

One possibility might be this:

$inputfile = FileOpen(@ScriptDir & "\input.txt", 0)
$outputfile = FileOpen(@ScriptDir & "\output.txt", 1)
Global $o
While 1
    $line = FileReadLine($inputfile)
    If @error Then ExitLoop
    $aRegEx = StringRegExp($line, ';(http:\/\/.*);.*;.*;', 1)
    If IsArray($aRegEx) Then $o &= $aRegEx[0] & @CRLF
Wend
FileWrite($outputfile, $o)
FileClose ($inputfile)
FileClose ($outputfile)

BR,

UEZ

This code example was useful to me as well; thanks very much.
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...