Extract text from every three lines using Windows

-4

0

I have a HUGE text file with details of my site users. (11GB+). It's built like that:

Email: example@gmail.com
Address: 1blahblahblahblah (Bitcoin Address).
Password: blahblahblah

Each of the details in a seperate line. (no spaces between them).

The detail I need is the Bitcoin address. I need them orginized in a text file, one after another.

Simply, I need a batch/java/whatever script that skips the first line, takes the Bitcoin address and puts it in a file, and then skips another line.. continuously.

I need the exported BTC addresses in a list, one address for each line.

The output I need:

1Exampleexampleexample

1Exampleexampleexample

1Exampleexampleexample

1Exampleexampleexample

Thanks in advance guys.

Mark

Posted 2015-05-26T17:09:19.313

Reputation: 1

1

Welcome to Super User. Unfortunately, we are not a code-writing service. Instead of simply asking for code to perform a particular task, please show us what you've tried so far (including any code you currently have) and where you're stuck so that we can help you with your specific problem. Questions that only ask for code are too broad and are likely to be put on hold or closed.

– DavidPostill – 2015-05-26T17:12:30.587

Answers

0

Here's a PowerShell script that will fetch every 2nd line (in groups of 3) and remove the superfluous text and the beginning and end of that line:

$fileToProcess = "C:\users\jsmith\Dropbox\neat scripts\userInfo.txt"
$fileToWrite = "C:\users\jsmith\Dropbox\neat scripts\bitcoin.txt" 
$reader = [System.IO.File]::OpenText($fileToProcess)
$lineCount = 1
try {
        for(;;) {                
            $line = $reader.ReadLine()
            if ($line -eq $null) { break }
            # process the line
            if ($lineCount -eq 2) {  
                $line = $line -replace "Address: "
                $line = $line -replace ' \(Bitcoin Address\).'
                Add-Content $fileToWrite ("`n"+$line)    
            }

            $lineCount = $lineCount+1
            if ($lineCount -gt 3) { $lineCount = 1}
        }
    }
    finally {
        $reader.Close()
    }

Per my normal caveat, do not test this without making a backup of the file you're parsing. I have tested this on my machine (with a much smaller file than the one you're parsing) and it shouldn't change the input file, however, your mileage may vary!

Trav

Posted 2015-05-26T17:09:19.313

Reputation: 908

I'm not sure how to run PowerShell scripts. I get this error using the PowerShell terminal: http://i.gyazo.com/36b80fdd2f7f37f6e7dfe1bb4d334022.png

– Mark – 2015-05-26T18:05:06.993

Your problem is that your PowerShell execution policy is set to restricted. (See this for details regarding PowerShell execution policies.) Close any PowerShell windows you currently have open. Search for PowerShell on the Start Menu, right click on it, and Run as Administrator... and launch it as an admin. Then type Set-ExecutionPolicy Unrestricted Assuming it runs ok, you can run the script I provided. (The easiest way is probably to copy and paste my code into PowerShell ISE and run it from there.)

– Trav – 2015-05-26T18:11:15.110

Okay. it did work this time, but the output included the "Address:" and I don't need it, I need only the addresses. Thanks for helping me out man – Mark – 2015-05-26T18:23:31.183

My assumption was wrong about your file actually having the words "Address: " in front of each line. I will edit the script to account for this. – Trav – 2015-05-26T18:24:44.473

Should work now. – Trav – 2015-05-26T18:57:15.200

Tried to run the new script and got this error: http://i.gyazo.com/1a2a7b220d8ac199aa1355742f093589.png Thanks again for helping me.

– Mark – 2015-05-26T18:59:12.057

Did you change the two variables for the input and output files at the top to match your actual files? Otherwise, I don't really know what the error is about. – Trav – 2015-05-26T19:01:38.230

the source file was opened in another program. issues fixed and your script works like a charm. Thanks A LOT man! I really appreciate it. – Mark – 2015-05-26T19:11:18.500

Glad it helped. Make sure to select the question as the answer. – Trav – 2015-05-26T19:19:09.537

0

How do I extract text from every third line?

The detail I need is the Bitcoin address. I need them orginized in a text file, one after another.

You can use findstr.

Note:

  • I don't have an 11GB file to test against.

Test data:

Email: example@gmail.com
Address: address 1 (Bitcoin Address).
Password: blahblahblah
Email: example@gmail.com
Address: address 2 (Bitcoin Address).
Password: blahblahblah
Email: example@gmail.com
Address: address 3 (Bitcoin Address).
Password: blahblahblah

Command:

findstr Address data.txt > address.out

Output:

C:\test>type address.out
Address: address 1 (Bitcoin Address).
Address: address 2 (Bitcoin Address).
Address: address 3 (Bitcoin Address).

Further Reading

DavidPostill

Posted 2015-05-26T17:09:19.313

Reputation: 118 938

0

FINDSTR - Search for strings in files.

findstr /I /C:"Address:" "HUGE text file.txt">"BTC addresses"

Next resource (required reading) (>, >> etc. special page) Redirection

JosefZ

Posted 2015-05-26T17:09:19.313

Reputation: 9 121